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; |