This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Fix array access beyond bounds in test cases


Hi,

I found that some test cases access arrays beyond their bounds.  I
looked up their originating bugzillas and found that the test
cases for pr22506 and pr34005 were likely to be typos since the
original test cases in the report do not have this problem.  For
pr31227 however, I am inclined to think that the test case is
incorrect.  I am not sure what the test case verifies since the array
accesses are obviously beyond bounds.

Regards,
Siddhesh

testsuite/ChangeLog:

2012-11-09  Siddhesh Poyarekar  <siddhesh@redhat.com>

	* gcc.dg/Warray-bounds-3.c (bar): Keep array access within
	bounds for ABDAY, DAY, ABMON, MON, AM_PM.
	* gcc.dg/vect/pr22506.c (foo): Reduce loop iterations to within
	array bounds.
	* gcc.dg/vect/pr34005.c (XdmcpUnwrap): Likewise.
diff --git a/gcc/testsuite/gcc.dg/Warray-bounds-3.c b/gcc/testsuite/gcc.dg/Warray-bounds-3.c
index 19cdb8e..773f463 100644
--- a/gcc/testsuite/gcc.dg/Warray-bounds-3.c
+++ b/gcc/testsuite/gcc.dg/Warray-bounds-3.c
@@ -34,31 +34,31 @@ bar (struct S *time)
   iov[1].iov_base = (void *) "def";
   iov[1].iov_len = 3;
 
-  for (cnt = 0; cnt <= 7; ++cnt)
+  for (cnt = 0; cnt < 7; ++cnt)
     {
       iov[2 + cnt].iov_base = (void *) (time->abday[cnt] ?: "");
       iov[2 + cnt].iov_len = strlen (iov[2 + cnt].iov_base) + 1;
     }
 
-  for (; cnt <= 14; ++cnt)
+  for (; cnt < 14; ++cnt)
     {
       iov[2 + cnt].iov_base = (void *) (time->day[cnt - 7] ?: "");
       iov[2 + cnt].iov_len = strlen (iov[2 + cnt].iov_base) + 1;
     }
 
-  for (; cnt <= 26; ++cnt)
+  for (; cnt < 26; ++cnt)
     {
       iov[2 + cnt].iov_base = (void *) (time->abmon[cnt - 14] ?: "");
       iov[2 + cnt].iov_len = strlen (iov[2 + cnt].iov_base) + 1;
     }
 
-  for (; cnt <= 38; ++cnt)
+  for (; cnt < 38; ++cnt)
     {
       iov[2 + cnt].iov_base = (void *) (time->mon[cnt - 26] ?: "");
       iov[2 + cnt].iov_len = strlen (iov[2 + cnt].iov_base) + 1;
     }
 
-  for (; cnt <= 40; ++cnt)
+  for (; cnt < 40; ++cnt)
     {
       iov[2 + cnt].iov_base =  (void *) (time->am_pm[cnt - 38] ?: "");
       iov[2 + cnt].iov_len = strlen (iov[2 + cnt].iov_base) + 1;
diff --git a/gcc/testsuite/gcc.dg/vect/pr22506.c b/gcc/testsuite/gcc.dg/vect/pr22506.c
index 5a2d749..a618e32 100644
--- a/gcc/testsuite/gcc.dg/vect/pr22506.c
+++ b/gcc/testsuite/gcc.dg/vect/pr22506.c
@@ -7,8 +7,8 @@ void foo()
 {
     int i;
 
-    for (i=0; i<5; ++i) x[i]=0;
-    for (i=0; i<4; ++i) ;
+    for (i=0; i<3; ++i) x[i]=0;
+    for (i=0; i<2; ++i) ;
 }
 
 /* { dg-final { cleanup-tree-dump "vect" } } */
diff --git a/gcc/testsuite/gcc.dg/vect/pr34005.c b/gcc/testsuite/gcc.dg/vect/pr34005.c
index 813f950..86c3832 100644
--- a/gcc/testsuite/gcc.dg/vect/pr34005.c
+++ b/gcc/testsuite/gcc.dg/vect/pr34005.c
@@ -8,7 +8,8 @@ void XdmcpUnwrap (unsigned char *output, int k)
   int i;
   unsigned char blocks[2][8];
   k = (k == 0) ? 1 : 0;
-  for (i = 0; i < 32; i++)
+
+  for (i = 0; i < 8; i++)
     output[i] = blocks[k][i];
 }
 

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]