<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: memcmp() in CW is broken in CodeWarrior for MCU</title>
    <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/HC12-memcmp-in-CW-is-broken/m-p/134216#M1545</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;Hello CrasyCat,&lt;/DIV&gt;&lt;DIV&gt;&lt;HR /&gt;CrasyCat wrote:&lt;BR /&gt;OK in that case submit a service request though our on line support web site....&lt;/DIV&gt;&lt;DIV&gt;&lt;HR /&gt;&lt;DIV&gt;Too late for me &lt;IMG alt=":smileymad:" class="emoticon emoticon-smileymad" id="smileymad" src="http://freescale.i.lithium.com/i/smilies/16x16_smiley-mad.gif" title="Smiley Mad" /&gt;&lt;/DIV&gt;&lt;DIV&gt;This bad 'memcmp' caused a bug in a cryptographic function&amp;nbsp;that was very hard to track down, but I already fixed it.&lt;/DIV&gt;&lt;DIV&gt;Nevertheless, I hope that&amp;nbsp;one of the Freescale compiler folks find this thread and correct the library.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Cheers,&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;-&amp;gt; pittbull&lt;/DIV&gt;&lt;DIV&gt;&lt;BR /&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 27 Oct 2006 02:08:34 GMT</pubDate>
    <dc:creator>pittbull</dc:creator>
    <dc:date>2006-10-27T02:08:34Z</dc:date>
    <item>
      <title>HC12: memcmp() in CW is broken</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/HC12-memcmp-in-CW-is-broken/m-p/134210#M1539</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt; &lt;/DIV&gt;&lt;P&gt;Hello,&lt;BR /&gt;I'm using CW for S12X (IDE version 5.7.0.1714).&lt;BR /&gt;The memcmp() function does not work correctly.&lt;BR /&gt;&lt;BR /&gt;Trying the below program on a Windows PC I get:&lt;BR /&gt;PASS!&lt;BR /&gt;PASS!&lt;BR /&gt;&lt;SPAN class="msg_source_code"&gt;&lt;SPAN class="text_smallest"&gt;Code:&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE&gt;int my_memcmp_impl (void *s1, void *s2, unsigned int n){unsigned char *cs1 = s1;unsigned char *cs2 = s2;for (;n-- &amp;gt; 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)) &amp;gt; 0)debug_printf ("!!!! FAIL !!!!\n");elsedebug_printf ("PASS!\n");debug_printf ("Testing memcmp (my implementation):\n");if (my_memcmp_impl(snonce, anonce, sizeof(snonce)) &amp;gt; 0)debug_printf ("!!!! FAIL !!!!\n");elsedebug_printf ("PASS!\n");debug_printf ("\n");}&lt;/PRE&gt;&lt;P&gt;&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;the same program running on an S12X target gives me&lt;BR /&gt;!!!! FAIL !!!!&lt;BR /&gt;PASS!&lt;/P&gt;&lt;P&gt;Message Edited by Alban on &lt;SPAN class="date_text"&gt;2006-10-26&lt;/SPAN&gt; &lt;SPAN class="time_text"&gt;11:37 AM&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Message Edited by CrasyCat on &lt;SPAN class="date_text"&gt;2007-04-13&lt;/SPAN&gt; &lt;SPAN class="time_text"&gt;01:29 PM&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 24 Oct 2006 21:48:03 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/HC12-memcmp-in-CW-is-broken/m-p/134210#M1539</guid>
      <dc:creator>pittbull</dc:creator>
      <dc:date>2006-10-24T21:48:03Z</dc:date>
    </item>
    <item>
      <title>Re: memcmp() in CW is broken</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/HC12-memcmp-in-CW-is-broken/m-p/134211#M1540</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;Hello&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;You have defined cs1 and cs2 as pointer to unsigned char.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;When you are doing the operation *cs1 - *cs2, the operation is performed on unsigned value (no sign extension done prior to performing the operation).&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;If you define cs1 and cs2 as pointer to signed char, you get the expected FAIL message.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;I hope this helps.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;CrasyCat&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 25 Oct 2006 16:23:01 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/HC12-memcmp-in-CW-is-broken/m-p/134211#M1540</guid>
      <dc:creator>CrasyCat</dc:creator>
      <dc:date>2006-10-25T16:23:01Z</dc:date>
    </item>
    <item>
      <title>Re: memcmp() in CW is broken</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/HC12-memcmp-in-CW-is-broken/m-p/134212#M1541</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;Or simply write&lt;BR /&gt;&lt;BR /&gt;return (int)*cs1 - (int)*cs2;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 26 Oct 2006 13:55:58 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/HC12-memcmp-in-CW-is-broken/m-p/134212#M1541</guid>
      <dc:creator>Lundin</dc:creator>
      <dc:date>2006-10-26T13:55:58Z</dc:date>
    </item>
    <item>
      <title>Re: memcmp() in CW is broken</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/HC12-memcmp-in-CW-is-broken/m-p/134213#M1542</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;Hello,&lt;BR /&gt;&lt;BR /&gt;From the C spec:&lt;BR /&gt;-----------------&lt;BR /&gt;7.21.4 Comparison functions&lt;BR /&gt;1 The sign of a nonzero value returned by the comparison functions memcmp, strcmp,&lt;BR /&gt;and strncmp is determined by the sign of the difference between the values of the first&lt;BR /&gt;pair of characters (both interpreted as unsigned char) that differ in the objects being&lt;BR /&gt;compared.&lt;BR /&gt;&lt;BR /&gt;As you can see, my function does the right thing but the CW library uses 'signed' comparison (which is wrong according to the ISO/IEC document&lt;IMG alt=":smileywink:" class="emoticon emoticon-smileywink" id="smileywink" src="http://freescale.i.lithium.com/i/smilies/16x16_smiley-wink.gif" title="Smiley Wink" /&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 26 Oct 2006 18:18:48 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/HC12-memcmp-in-CW-is-broken/m-p/134213#M1542</guid>
      <dc:creator>pittbull</dc:creator>
      <dc:date>2006-10-26T18:18:48Z</dc:date>
    </item>
    <item>
      <title>Re: memcmp() in CW is broken</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/HC12-memcmp-in-CW-is-broken/m-p/134214#M1543</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;I agree with pittbull, it seems that CW does the memcmp() wrong.&lt;/DIV&gt;&lt;DIV&gt;I did a test on CW S12X v. 4.5 and when comparing two strings beginning with 0x0b and 0xd8, memcmp returns 0x33 which is a positive integer suggesting that 0x0b &amp;gt; 0xd8.&lt;/DIV&gt;&lt;DIV&gt;The right return value would have been 0xff35.&lt;/DIV&gt;&lt;P&gt;Message Edited by Sten on &lt;SPAN class="date_text"&gt;2006-10-26&lt;/SPAN&gt;&lt;SPAN class="time_text"&gt;03:33 PM&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 26 Oct 2006 19:31:54 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/HC12-memcmp-in-CW-is-broken/m-p/134214#M1543</guid>
      <dc:creator>Sten</dc:creator>
      <dc:date>2006-10-26T19:31:54Z</dc:date>
    </item>
    <item>
      <title>Re: memcmp() in CW is broken</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/HC12-memcmp-in-CW-is-broken/m-p/134215#M1544</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;Hello&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;OK in that case submit a service request though our on line support web site.&lt;/DIV&gt;&lt;DIV&gt;This way the defect will be processed appropriately by our support team.&lt;/DIV&gt;&lt;DIV&gt;CrasyCat&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 26 Oct 2006 20:34:17 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/HC12-memcmp-in-CW-is-broken/m-p/134215#M1544</guid>
      <dc:creator>CrasyCat</dc:creator>
      <dc:date>2006-10-26T20:34:17Z</dc:date>
    </item>
    <item>
      <title>Re: memcmp() in CW is broken</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/HC12-memcmp-in-CW-is-broken/m-p/134216#M1545</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;Hello CrasyCat,&lt;/DIV&gt;&lt;DIV&gt;&lt;HR /&gt;CrasyCat wrote:&lt;BR /&gt;OK in that case submit a service request though our on line support web site....&lt;/DIV&gt;&lt;DIV&gt;&lt;HR /&gt;&lt;DIV&gt;Too late for me &lt;IMG alt=":smileymad:" class="emoticon emoticon-smileymad" id="smileymad" src="http://freescale.i.lithium.com/i/smilies/16x16_smiley-mad.gif" title="Smiley Mad" /&gt;&lt;/DIV&gt;&lt;DIV&gt;This bad 'memcmp' caused a bug in a cryptographic function&amp;nbsp;that was very hard to track down, but I already fixed it.&lt;/DIV&gt;&lt;DIV&gt;Nevertheless, I hope that&amp;nbsp;one of the Freescale compiler folks find this thread and correct the library.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Cheers,&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;-&amp;gt; pittbull&lt;/DIV&gt;&lt;DIV&gt;&lt;BR /&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 27 Oct 2006 02:08:34 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/HC12-memcmp-in-CW-is-broken/m-p/134216#M1545</guid>
      <dc:creator>pittbull</dc:creator>
      <dc:date>2006-10-27T02:08:34Z</dc:date>
    </item>
    <item>
      <title>Re: memcmp() in CW is broken</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/HC12-memcmp-in-CW-is-broken/m-p/134217#M1546</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;I assume that you have this enabled:&lt;BR /&gt;&lt;BR /&gt;Edit-&amp;gt;Project settings-&amp;gt;Type sizes-&amp;gt; char = signed&lt;BR /&gt;&lt;BR /&gt;In ANSI C, the char type or may not be signed by default. On the other hand, one would have to assume that Metrowerks have adapted their function to suit the compiler's default char type.&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 27 Oct 2006 14:58:23 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/HC12-memcmp-in-CW-is-broken/m-p/134217#M1546</guid>
      <dc:creator>Lundin</dc:creator>
      <dc:date>2006-10-27T14:58:23Z</dc:date>
    </item>
    <item>
      <title>Re: memcmp() in CW is broken</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/HC12-memcmp-in-CW-is-broken/m-p/134218#M1547</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;Lundin wrote:&lt;BR /&gt;In ANSI C, the char type or may not be signed by default.&lt;BR /&gt;&lt;BR /&gt;Yes, it's implementation-defined but 'memcmp' must treat the input as unsigned...&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 28 Oct 2006 01:19:10 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/HC12-memcmp-in-CW-is-broken/m-p/134218#M1547</guid>
      <dc:creator>pittbull</dc:creator>
      <dc:date>2006-10-28T01:19:10Z</dc:date>
    </item>
  </channel>
</rss>

