libstdc++: Fix buffer overflows in tests [PR 99382]
authorJonathan Wakely <jwakely@redhat.com>
Thu, 4 Mar 2021 10:28:38 +0000 (10:28 +0000)
committerJonathan Wakely <jwakely@redhat.com>
Thu, 4 Mar 2021 10:31:27 +0000 (10:31 +0000)
This seems to be a typo/thinko in the definition of the arrays used as
storage.

libstdc++-v3/ChangeLog:

PR libstdc++/99382
* testsuite/20_util/specialized_algorithms/uninitialized_default_n/sizes.cc:
Make storage larger than required. Verify no write to the last
element.
* testsuite/20_util/specialized_algorithms/uninitialized_value_construct_n/sizes.cc:
Likewise.

libstdc++-v3/testsuite/20_util/specialized_algorithms/uninitialized_default_n/sizes.cc
libstdc++-v3/testsuite/20_util/specialized_algorithms/uninitialized_value_construct_n/sizes.cc

index fbe14d4..1a1aba4 100644 (file)
@@ -41,10 +41,12 @@ test02()
     int operator>(void*) { return value != 0; }
   };
 
-  int i[3];
+  int i[5] = { 1, 2, 3, 4, 5 };
   Size n = {4};
   auto j = std::__uninitialized_default_n(i, n);
   VERIFY( j == (i + 4) );
+  // i[0:3] are default-initialized so have indeterminate values.
+  VERIFY( i[4] == 5 );
 }
 
 int
index d227de4..5833f7e 100644 (file)
@@ -42,10 +42,15 @@ test02()
     int operator>(void*) { return value != 0; }
   };
 
-  int i[3];
+  int i[5] = { 1, 2, 3, 4, 5 };
   Size n = {4};
   auto j = std::__uninitialized_default_n(i, n);
   VERIFY( j == (i + 4) );
+  VERIFY( i[0] == 0 );
+  VERIFY( i[1] == 0 );
+  VERIFY( i[2] == 0 );
+  VERIFY( i[3] == 0 );
+  VERIFY( i[4] == 5 );
 }
 
 int