I think I had responded to a similar change using strncmp some time back regarding embedded NULL characters.
Regarding memcmp/memmove usage, the behavior would be defined with memmove if source and destination overlap. I don't think this should be the case in the compiler but you never know. Murthy -----Original Message----- From: Mike Murphy [mailto:mmur...@nvidia.com] Sent: Thursday, September 23, 2010 3:27 PM To: 'David Coakley'; open64-devel Subject: Re: [Open64-devel] a memory copy bug in util/flags.c I'm curious why you use memmove rather than memcpy? -----Original Message----- From: David Coakley [mailto:dcoak...@gmail.com] Sent: Thursday, September 23, 2010 3:20 PM To: open64-devel Subject: [Open64-devel] a memory copy bug in util/flags.c Hi all, We recently tracked a large performance regression to trunk commit r3289. That was a change to replace some assignments with calls to strncpy() in util/flags.c. I think that using strncpy() is incorrect: we are copying binary data but strncpy() will stop copying at the first null byte in the source and then pad the destination with null bytes. The apparent effect is that some internal compiler options are getting truncated/corrupted. I include a proposed fix below that changes strncpy() to memmove(). I have tested that it does indeed restore performance for the benchmark under test. Could a gatekeeper please review it? Steve, your review would be appreciated as well. Thanks, -David Coakley / AMD Open Source Compiler Engineering Index: osprey/common/util/flags.c =================================================================== --- osprey/common/util/flags.c (revision 3358) +++ osprey/common/util/flags.c (working copy) @@ -377,7 +377,7 @@ OPTVALTYPES v; if (Get_OVK_Size(o) > 0) - strncpy((void *) &v, p, Get_OVK_Size(o)); + memmove(&v, p, Get_OVK_Size(o)); switch (o) { case OVK_NONE: @@ -405,7 +405,7 @@ { OPTVALTYPES v; if (OVK_Pointer_Kind(o)) { - strncpy((void *) &v, p, Get_OVK_Size(o)); + memmove(&v, p, Get_OVK_Size(o)); return (void *) v.p; } else @@ -428,9 +428,9 @@ if (size > 0) { if (save) - strncpy(container, var, size); + memmove(container, var, size); else /* restore */ - strncpy(var, container, size); + memmove(var, container, size); } return size; @@ -676,7 +676,7 @@ break; } if (Get_OVK_Size(ODESC_kind(odesc)) > 0) - strncpy(var, (void *) &v, Get_OVK_Size(ODESC_kind(odesc))); + memmove(var, &v, Get_OVK_Size(ODESC_kind(odesc))); } /* ==================================================================== ------------------------------------------------------------------------ ------ Nokia and AT&T present the 2010 Calling All Innovators-North America contest Create new apps & games for the Nokia N8 for consumers in U.S. and Canada $10 million total in prizes - $4M cash, 500 devices, nearly $6M in marketing Develop with Nokia Qt SDK, Web Runtime, or Java and Publish to Ovi Store http://p.sf.net/sfu/nokia-dev2dev _______________________________________________ Open64-devel mailing list Open64-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/open64-devel ------------------------------------------------------------------------ ----------- This email message is for the sole use of the intended recipient(s) and may contain confidential information. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message. ------------------------------------------------------------------------ ----------- ------------------------------------------------------------------------ ------ Nokia and AT&T present the 2010 Calling All Innovators-North America contest Create new apps & games for the Nokia N8 for consumers in U.S. and Canada $10 million total in prizes - $4M cash, 500 devices, nearly $6M in marketing Develop with Nokia Qt SDK, Web Runtime, or Java and Publish to Ovi Store http://p.sf.net/sfu/nokia-dev2dev _______________________________________________ Open64-devel mailing list Open64-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/open64-devel ------------------------------------------------------------------------------ Nokia and AT&T present the 2010 Calling All Innovators-North America contest Create new apps & games for the Nokia N8 for consumers in U.S. and Canada $10 million total in prizes - $4M cash, 500 devices, nearly $6M in marketing Develop with Nokia Qt SDK, Web Runtime, or Java and Publish to Ovi Store http://p.sf.net/sfu/nokia-dev2dev _______________________________________________ Open64-devel mailing list Open64-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/open64-devel