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

Reply via email to