]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Fix undefined behaviour in testsuite
authorJonathan Wakely <jwakely@redhat.com>
Tue, 4 May 2021 14:28:39 +0000 (15:28 +0100)
committerJonathan Wakely <jwakely@redhat.com>
Thu, 6 May 2021 13:05:34 +0000 (14:05 +0100)
Fix some test bugs found by ubsan.

libstdc++-v3/ChangeLog:

* testsuite/20_util/from_chars/3.cc: Use unsigned type to avoid
overflow.
* testsuite/24_iterators/reverse_iterator/2.cc: Do not add
non-zero value to null pointer.
* testsuite/25_algorithms/copy_backward/move_iterators/69478.cc:
Use past-the-end iterator for result.
* testsuite/25_algorithms/move_backward/69478.cc: Likewise.
* testsuite/25_algorithms/move_backward/93872.cc: Likewise.

(cherry picked from commit 6fb8b67089119b737ccb38f75f403b8d279e2229)

libstdc++-v3/testsuite/20_util/from_chars/3.cc
libstdc++-v3/testsuite/24_iterators/reverse_iterator/2.cc
libstdc++-v3/testsuite/25_algorithms/copy_backward/move_iterators/69478.cc
libstdc++-v3/testsuite/25_algorithms/move_backward/69478.cc
libstdc++-v3/testsuite/25_algorithms/move_backward/93872.cc

index c99353a7284400e205b2398c72e56d41080e41b0..d3d70394ed949896911afc4e3ed153840acccd7d 100644 (file)
@@ -29,7 +29,7 @@ long long
 read(const char* first, const char* last, int base)
 {
   long long val = 0;
-  long long place = 1;
+  unsigned long long place = 1;
   while (last > first)
   {
     val += (*--last - '0') * place;
index a6d7d6b019135be5b04254a4df1773cd9552a2ed..633c1426b965048439e6d30eed72ddc6b003daa1 100644 (file)
@@ -27,7 +27,7 @@ void test02()
   iterator_type it01;
   iterator_type it02;
 
-  // Sanity check non-member operators and functions can be instantiated. 
+  // Sanity check non-member operators and functions can be instantiated.
   it01 == it02;
   it01 != it02;
   it01 < it02;
@@ -35,11 +35,11 @@ void test02()
   it01 > it02;
   it01 >= it02;
   it01 - it02;
-  5 + it02;
+  0 + it02;
 }
 
-int main() 
-{ 
+int main()
+{
   test02();
   return 0;
 }
index 88a01b84a8ebac193f8ac45dbd55b4133e19d127..9c84cfb176c82403bb1c5d234215d6fd6dc87c59 100644 (file)
@@ -35,6 +35,6 @@ test01()
   static_assert(std::is_trivial<trivial_rvalstruct>::value, "");
 
   trivial_rvalstruct a[1], b[1];
-  copy_backward(std::make_move_iterator(a), std::make_move_iterator(a+1), b);
+  copy_backward(std::make_move_iterator(a), std::make_move_iterator(a+1), b+1);
 }
 // { dg-prune-output "use of deleted" }
index 25bfe29fc1443eee3a55d0c5bd18bb5f088112e7..10e31be1e08c3c28fa10f8952accb4d097730b8d 100644 (file)
@@ -35,6 +35,6 @@ test01()
   static_assert(std::is_trivial<trivial_rvalstruct>::value, "");
 
   trivial_rvalstruct a[1], b[1];
-  std::move_backward(a, a + 1, b);
+  std::move_backward(a, a + 1, b + 1);
 }
 // { dg-prune-output "use of deleted" }
index df96c94b39430d1e8f500e9b6f8b03552ee9fc2e..a9fd2697f5b1495a8de5d40f1ac8e6a2247a152b 100644 (file)
@@ -35,5 +35,5 @@ void
 test01()
 {
   X a[2], b[2];
-  std::move_backward(std::begin(a), std::end(a), std::begin(b));
+  std::move_backward(std::begin(a), std::end(a), std::end(b));
 }