libstdc++: std::basic_regex should treat '\0' as an ordinary char [PR84110]
authorJonathan Wakely <jwakely@redhat.com>
Wed, 29 Sep 2021 12:48:11 +0000 (13:48 +0100)
committerJonathan Wakely <jwakely@redhat.com>
Wed, 29 Sep 2021 12:48:11 +0000 (13:48 +0100)
commitb701e1f8f6870c0f8cb4050674da489101dd05a5
tree890c89e93d92bf94e4028a2c309be6cfe012ba0e
parentb59be1adbaea022f19dc7c30d9bf5089e80795d9
libstdc++: std::basic_regex should treat '\0' as an ordinary char [PR84110]

When the input sequence contains a _CharT(0) character, the strchr call
in _Scanner<_CharT>::_M_scan_normal() will search for '\0' and so return
a pointer to the terminating null at the end of the string. This makes
the scanner think it's found a special character. Because it doesn't
match any of the actual special characters, we fall off the end of the
function (or assert in debug mode).

We should check for a null character explicitly and either treat it as
an ordinary character (for the ECMAScript grammar) or an error (for all
others). I'm not 100% sure that's right, but it seems consistent with
the POSIX RE rules where a '\0' means the end of the regex pattern or
the end of the sequence being matched.

Signed-off-by: Jonathan Wakely <jwakely@redhat.com>
libstdc++-v3/ChangeLog:

PR libstdc++/84110
* include/bits/regex_error.h (regex_constants::_S_null): New
error code for internal use.
* include/bits/regex_scanner.tcc (_Scanner::_M_scan_normal()):
Check for null character.
* testsuite/28_regex/basic_regex/84110.cc: New test.
libstdc++-v3/include/bits/regex_error.h
libstdc++-v3/include/bits/regex_scanner.tcc
libstdc++-v3/testsuite/28_regex/basic_regex/84110.cc [new file with mode: 0644]