From 8d8e8f3ad567c7bd1de708fcc841f691d9686c4d Mon Sep 17 00:00:00 2001 From: Jonathan Wakely Date: Thu, 21 Jul 2016 20:38:51 +0100 Subject: [PATCH] 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. --- .../21_strings/basic_string/modifiers/append/wchar_t/1.cc | 2 +- .../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