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-10572] libstdc++: Fix out-of-bound array accesses in testsuite
Date: Tue, 26 Apr 2022 13:12:51 +0000 (GMT)	[thread overview]
Message-ID: <20220426131251.586A63858430@sourceware.org> (raw)

https://gcc.gnu.org/g:021540f17b80599adb1aa1475141d456a5194626

commit r10-10572-g021540f17b80599adb1aa1475141d456a5194626
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Thu Jul 21 20:38:51 2016 +0100

    libstdc++: Fix out-of-bound array accesses in testsuite
    
    I fixed some undefined behaviour in string tests in r238609, but I only
    fixed the narrow char versions. This applies the same fixes to the
    wchar_t ones. These problems were found when testing a patch to make
    std::basic_string usable in constexpr.
    
    libstdc++-v3/ChangeLog:
    
            * testsuite/21_strings/basic_string/modifiers/append/wchar_t/1.cc:
            Fix reads past the end of strings.
            * testsuite/21_strings/basic_string/operations/compare/wchar_t/1.cc:
            Likewise.
            * testsuite/experimental/string_view/operations/compare/wchar_t/1.cc:
            Likewise.
    
    (cherry picked from commit 8d8e8f3ad567c7bd1de708fcc841f691d9686c4d)

Diff:
---
 .../testsuite/21_strings/basic_string/modifiers/append/wchar_t/1.cc   | 2 +-
 .../testsuite/21_strings/basic_string/operations/compare/wchar_t/1.cc | 4 ++--
 .../experimental/string_view/operations/compare/wchar_t/1.cc          | 4 ++--
 3 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/modifiers/append/wchar_t/1.cc b/libstdc++-v3/testsuite/21_strings/basic_string/modifiers/append/wchar_t/1.cc
index 604f94238f5..88e34c4881a 100644
--- a/libstdc++-v3/testsuite/21_strings/basic_string/modifiers/append/wchar_t/1.cc
+++ b/libstdc++-v3/testsuite/21_strings/basic_string/modifiers/append/wchar_t/1.cc
@@ -117,7 +117,7 @@ void test01(void)
   VERIFY( str06 == L"corpus, corpus" );
 
   str06 = str02;
-  str06.append(L"corpus, ", 12);
+  str06.append(L"corpus, ", 9); // n=9 includes null terminator
   VERIFY( str06 != L"corpus, corpus, " );
 
 
diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/operations/compare/wchar_t/1.cc b/libstdc++-v3/testsuite/21_strings/basic_string/operations/compare/wchar_t/1.cc
index ad9120ef200..5abfabf2075 100644
--- a/libstdc++-v3/testsuite/21_strings/basic_string/operations/compare/wchar_t/1.cc
+++ b/libstdc++-v3/testsuite/21_strings/basic_string/operations/compare/wchar_t/1.cc
@@ -81,8 +81,8 @@ test01()
   test_value(wcsncmp(str_1.data(), str_0.data(), 6), z);
   test_value(wcsncmp(str_1.data(), str_0.data(), 14), lt);
   test_value(wmemcmp(str_1.data(), str_0.data(), 6), z);
-  test_value(wmemcmp(str_1.data(), str_0.data(), 14), lt);
-  test_value(wmemcmp(L"costa marbella", L"costa rica", 14), lt);
+  test_value(wmemcmp(str_1.data(), str_0.data(), 10), lt);
+  test_value(wmemcmp(L"costa marbella", L"costa rica", 10), lt);
 
   // int compare(const basic_string& str) const;
   test_value(str_0.compare(str_1), gt); //because r>m
diff --git a/libstdc++-v3/testsuite/experimental/string_view/operations/compare/wchar_t/1.cc b/libstdc++-v3/testsuite/experimental/string_view/operations/compare/wchar_t/1.cc
index 52d10e199df..c15f4da5241 100644
--- a/libstdc++-v3/testsuite/experimental/string_view/operations/compare/wchar_t/1.cc
+++ b/libstdc++-v3/testsuite/experimental/string_view/operations/compare/wchar_t/1.cc
@@ -81,8 +81,8 @@ test01()
   test_value(wcsncmp(str_1.data(), str_0.data(), 6), z);
   test_value(wcsncmp(str_1.data(), str_0.data(), 14), lt);
   test_value(wmemcmp(str_1.data(), str_0.data(), 6), z);
-  test_value(wmemcmp(str_1.data(), str_0.data(), 14), lt);
-  test_value(wmemcmp(L"costa marbella", L"costa rica", 14), lt);
+  test_value(wmemcmp(str_1.data(), str_0.data(), 10), lt);
+  test_value(wmemcmp(L"costa marbella", L"costa rica", 10), lt);
 
   // int compare(const basic_string_view& str) const;
   test_value(str_0.compare(str_1), gt); //because r>m


                 reply	other threads:[~2022-04-26 13:12 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=20220426131251.586A63858430@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).