[Bug libstdc++/113202] std::find does not work with the maximum range of pointers
redi at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Wed Jan 3 11:19:00 GMT 2024
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113202
--- Comment #11 from Jonathan Wakely <redi at gcc dot gnu.org> ---
s + OFFSET has undefined behaviour.
With -O2 or -O3 GCC even tells you where the problem is:
find_bug.cpp: In function 'int main(int, char**)':
find_bug.cpp:39:61: warning: array subscript 1048576 is outside array bounds of
'const char [6]' [-Warray-bounds=]
39 | std::cout << "strlen = " << strlen_no_ranges(s, s + OFFSET) << ", no
ranges, OFFSET = " << OFFSET << std::endl;
| ^
find_bug.cpp:40:58: warning: array subscript 1048576 is outside array bounds of
'const char [6]' [-Warray-bounds=]
40 | std::cout << "strlen = " << strlen_ranges(s, s + OFFSET) << ",
ranges, OFFSET = " << OFFSET << std::endl;
|
More information about the Gcc-bugs
mailing list