[TESTSUITE]Use memcpy instead of strcpy in testsuite/gcc.dg/memcmp-1.c
authorRenlin Li <renlin.li@arm.com>
Thu, 31 Aug 2017 09:18:22 +0000 (09:18 +0000)
committerRenlin Li <renlin@gcc.gnu.org>
Thu, 31 Aug 2017 09:18:22 +0000 (09:18 +0000)
strcpy will keep reading and writing memory if the string is not terminated
with null character. In this case, it may visit memory beyond the boundary.

gcc/testsuite/

2017-08-31  Renlin Li  <renlin.li@arm.com>
    Aaron Sawdey  <acsawdey@linux.vnet.ibm.com>

* gcc.dg/memcmp-1.c (test_strncmp): Use memcpy instead of strcpy.

Co-Authored-By: Aaron Sawdey <acsawdey@linux.vnet.ibm.com>
From-SVN: r251554

gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/memcmp-1.c

index afaa91943caf52fe40061ee170b795218c6ac25a..98b269e3dbfa44e8241b4da9842630f90017fa26 100644 (file)
@@ -1,3 +1,8 @@
+2017-08-31  Renlin Li  <renlin.li@arm.com>
+           Aaron Sawdey  <acsawdey@linux.vnet.ibm.com>
+
+       * gcc.dg/memcmp-1.c: Use memcpy instead of strcpy.
+
 2017-08-30  Bill Schmidt  <wschmidt@linux.vnet.ibm.com>
 
        PR tree-optimization/81987
index 828a0caf1350ed5b5b02154035b2d23151560f11..ace7173f754a7014e24cc3722afa1c94297ce9a1 100644 (file)
@@ -110,8 +110,8 @@ static void test_strncmp_ ## SZ ## _ ## ALIGN (const char *str1, const char *str
        {                                                               \
          a = three+i*ALIGN+j*(4096-2*i*ALIGN);                         \
          b = four+i*ALIGN+j*(4096-2*i*ALIGN);                          \
-         strcpy(a,str1);                                               \
-         strcpy(b,str2);                                               \
+         memcpy(a,str1,SZ);                                            \
+         memcpy(b,str2,SZ);                                            \
          r = strncmp(a,b,SZ);                                          \
          if ( r < 0 && !(expect < 0) ) abort();                        \
          if ( r > 0 && !(expect > 0) ) abort();                        \