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 r12-5304] libstdc++: Fix out-of-bound array accesses in testsuite Date: Tue, 16 Nov 2021 14:16:52 +0000 (GMT) [thread overview] Message-ID: <20211116141652.74E3A385AC33@sourceware.org> (raw) https://gcc.gnu.org/g:8d8e8f3ad567c7bd1de708fcc841f691d9686c4d commit r12-5304-g8d8e8f3ad567c7bd1de708fcc841f691d9686c4d 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. 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 bb2d682de8e..684209f143e 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 27836f8e6fb..6f2113fb16a 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 db523e6a83c..20bb030970b 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:[~2021-11-16 14:16 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=20211116141652.74E3A385AC33@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: linkBe 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).