string::iterator should have more error checking

Jonathan Wakely jwakely@redhat.com
Fri Jun 24 09:35:03 GMT 2022


On Fri, 24 Jun 2022 at 10:06, Frederick Virchanza Gotham
<cauldwell.thomas@gmail.com> wrote:
>
> On Thu, Jun 23, 2022 at 11:36 PM Jonathan Wakely <jwakely@redhat.com> wrote:
>
> > Yes it does:
> > https://godbolt.org/z/hYhcfjTWY
>
>
> You're right, that does work.
>
> I've put together another little sample program. The dereferencing of
> an "end()" iterator is flagged by __gnu_debug::_Safe_iterator, however
> the invalid memory access on the last line -- strangely -- is not
> noticed by "-fsanitize"
>
>         https://godbolt.org/z/4nzjGG8o3

That's expected. The contents of the string_view are a string literal,
which is in the program image, not on the heap. AddressSanitizer
doesn't check access to such memory.
The byte after the string literal "brush" is uninitialized, but it
does exist in a valid memory page.

And it's not detected by Debug Mode because string_view iterators are
just pointers.



More information about the Libstdc++ mailing list