public inbox for libstdc++-cvs@sourceware.org
help / color / mirror / Atom feed
From: Jonathan Wakely <redi@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org
Subject: [gcc r10-9938] libstdc++: Fix undefined behaviour in testsuite
Date: Fri, 18 Jun 2021 12:56:34 +0000 (GMT)	[thread overview]
Message-ID: <20210618125634.279BE3AA7C8F@sourceware.org> (raw)

https://gcc.gnu.org/g:e50a64c98316eac1dfb695d903cc7cda0cfcb389

commit r10-9938-ge50a64c98316eac1dfb695d903cc7cda0cfcb389
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Tue May 4 15:28:39 2021 +0100

    libstdc++: Fix undefined behaviour in testsuite
    
    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)

Diff:
---
 libstdc++-v3/testsuite/20_util/from_chars/3.cc                    | 2 +-
 libstdc++-v3/testsuite/24_iterators/reverse_iterator/2.cc         | 8 ++++----
 .../testsuite/25_algorithms/copy_backward/move_iterators/69478.cc | 2 +-
 libstdc++-v3/testsuite/25_algorithms/move_backward/69478.cc       | 2 +-
 libstdc++-v3/testsuite/25_algorithms/move_backward/93872.cc       | 2 +-
 5 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/libstdc++-v3/testsuite/20_util/from_chars/3.cc b/libstdc++-v3/testsuite/20_util/from_chars/3.cc
index 9d4a77f5c31..d1f93bba2cb 100644
--- a/libstdc++-v3/testsuite/20_util/from_chars/3.cc
+++ b/libstdc++-v3/testsuite/20_util/from_chars/3.cc
@@ -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;
diff --git a/libstdc++-v3/testsuite/24_iterators/reverse_iterator/2.cc b/libstdc++-v3/testsuite/24_iterators/reverse_iterator/2.cc
index 29c4a5aae25..54e9f79bdd2 100644
--- a/libstdc++-v3/testsuite/24_iterators/reverse_iterator/2.cc
+++ b/libstdc++-v3/testsuite/24_iterators/reverse_iterator/2.cc
@@ -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;
 }
diff --git a/libstdc++-v3/testsuite/25_algorithms/copy_backward/move_iterators/69478.cc b/libstdc++-v3/testsuite/25_algorithms/copy_backward/move_iterators/69478.cc
index 1d779df10d6..2ed14fe110a 100644
--- a/libstdc++-v3/testsuite/25_algorithms/copy_backward/move_iterators/69478.cc
+++ b/libstdc++-v3/testsuite/25_algorithms/copy_backward/move_iterators/69478.cc
@@ -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" }
diff --git a/libstdc++-v3/testsuite/25_algorithms/move_backward/69478.cc b/libstdc++-v3/testsuite/25_algorithms/move_backward/69478.cc
index c9690288fee..ef28722a3ce 100644
--- a/libstdc++-v3/testsuite/25_algorithms/move_backward/69478.cc
+++ b/libstdc++-v3/testsuite/25_algorithms/move_backward/69478.cc
@@ -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" }
diff --git a/libstdc++-v3/testsuite/25_algorithms/move_backward/93872.cc b/libstdc++-v3/testsuite/25_algorithms/move_backward/93872.cc
index 69774fa86c6..e16de82ce31 100644
--- a/libstdc++-v3/testsuite/25_algorithms/move_backward/93872.cc
+++ b/libstdc++-v3/testsuite/25_algorithms/move_backward/93872.cc
@@ -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));
 }


                 reply	other threads:[~2021-06-18 12:56 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210618125634.279BE3AA7C8F@sourceware.org \
    --to=redi@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    --cc=libstdc++-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).