libstdc++: Fix out-of-bound array accesses in testsuite
authorJonathan Wakely <jwakely@redhat.com>
Thu, 21 Jul 2016 19:38:51 +0000 (20:38 +0100)
committerJonathan Wakely <jwakely@redhat.com>
Tue, 16 Nov 2021 14:09:00 +0000 (14:09 +0000)
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.

libstdc++-v3/testsuite/21_strings/basic_string/modifiers/append/wchar_t/1.cc
libstdc++-v3/testsuite/21_strings/basic_string/operations/compare/wchar_t/1.cc
libstdc++-v3/testsuite/experimental/string_view/operations/compare/wchar_t/1.cc

index bb2d682..684209f 100644 (file)
@@ -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, " );
 
 
index 27836f8..6f2113f 100644 (file)
@@ -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
index db523e6..20bb030 100644 (file)
@@ -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