[PATCH 6/6] libstdc++: Fix sizeof(wide-string)-1 bug in std::regex test
Tomasz Kaminski
tkaminsk@redhat.com
Wed Oct 1 14:03:10 GMT 2025
On Wed, Oct 1, 2025 at 2:40 PM Jonathan Wakely <jwakely@redhat.com> wrote:
> This uses sizeof on a wide string to get the length, which is wrong
> because each wchar_t is more than one byte. This was presumably copied
> from a narrow char test.
>
> libstdc++-v3/ChangeLog:
>
> * testsuite/28_regex/basic_regex/assign/wchar_t/pstring.cc: Use
> wcslen(cs) instead of sizeof(cs)-1.
> ---
>
> Tested powerpc64le-linux.
>
LGTM
>
> .../testsuite/28_regex/basic_regex/assign/wchar_t/pstring.cc | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git
> a/libstdc++-v3/testsuite/28_regex/basic_regex/assign/wchar_t/pstring.cc
> b/libstdc++-v3/testsuite/28_regex/basic_regex/assign/wchar_t/pstring.cc
> index 2e9dea13a774..91e55129908c 100644
> --- a/libstdc++-v3/testsuite/28_regex/basic_regex/assign/wchar_t/pstring.cc
> +++ b/libstdc++-v3/testsuite/28_regex/basic_regex/assign/wchar_t/pstring.cc
> @@ -23,6 +23,7 @@
> // [28.8.3] class template basic_regex assign()
>
> #include <regex>
> +#include <cwchar>
>
> // Tests assign operation from a Pascal-style counted-string.
> void test01()
> @@ -31,7 +32,7 @@ void test01()
>
> const wchar_t cs[] = L"aab";
> test_type re;
> - re.assign(cs, sizeof(cs)-1, std::regex_constants::basic);
> + re.assign(cs, std::wcslen(cs), std::regex_constants::basic);
> }
>
> int
> --
> 2.51.0
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://gcc.gnu.org/pipermail/libstdc++/attachments/20251001/313bb9d3/attachment.htm>
More information about the Libstdc++
mailing list