no name

HC12: memcmp() in CW is broken

Discussion created by no name on Oct 24, 2006
Latest reply on Oct 27, 2006 by no name

I'm using CW for S12X (IDE version
The memcmp() function does not work correctly.

Trying the below program on a Windows PC I get:

int my_memcmp_impl (void *s1, void *s2, unsigned int n){unsigned char *cs1 = s1;unsigned char *cs2 = s2;for (;n-- > 0; cs1++, cs2++)if (*cs1 != *cs2)return *cs1 - *cs2;return 0;}void test_memcmp (void){static unsigned char snonce[] = {0x0b, 0x97, 0x39, 0x0f, 0x37, 0x51, 0x78, 0x09, 0x81, 0x1e, 0xfd, 0x9c, 0x6e, 0x65, 0x94, 0x2b, 0x63, 0x2c, 0xe9, 0x53, 0x89, 0x38, 0x08, 0xba, 0x36, 0x0b, 0x03, 0x7c, 0xd1, 0x85, 0xe4, 0x14, };static unsigned char anonce[] = {0xd8, 0xa4, 0x80, 0x43, 0xb8, 0x37, 0x74, 0x02, 0xb9, 0x6a, 0xff, 0x49, 0xa5, 0x08, 0x9e, 0x93, 0x29, 0x37, 0x03, 0x47, 0x0e, 0xee, 0xa3, 0x17, 0xb4, 0x74, 0x30, 0xc6, 0xa6, 0x8d, 0x75, 0x2e, };debug_printf ("Testing memcmp (CW):\n");if (memcmp(snonce, anonce, sizeof(snonce)) > 0)debug_printf ("!!!! FAIL !!!!\n");elsedebug_printf ("PASS!\n");debug_printf ("Testing memcmp (my implementation):\n");if (my_memcmp_impl(snonce, anonce, sizeof(snonce)) > 0)debug_printf ("!!!! FAIL !!!!\n");elsedebug_printf ("PASS!\n");debug_printf ("\n");}

the same program running on an S12X target gives me
!!!! FAIL !!!!

Message Edited by Alban on 2006-10-26 11:37 AM

Message Edited by CrasyCat on 2007-04-13 01:29 PM