string::iterator should have more error checking

Frederick Virchanza Gotham cauldwell.thomas@gmail.com
Fri Jun 24 11:14:19 GMT 2022


On Fri, Jun 24, 2022 at 11:28 AM Jonathan Wakely <jwakely@redhat.com> wrote:

> But &*(s2.cend() + 1u) accesses the byte after the null, doesn't it?


It dereferences a pointer to the byte after the null, certainly, but
there isn't actually any reading/writing of the byte after the null.
I'm pretty sure that's why "-fsanitize" doesn't notice a problem.

However . . . check out the following:

        https://godbolt.org/z/jPcv9M6e3

Strangely it doesn't mind printing an invalid "uintptr_t", but it does
mind printing an invalid pointer.


> I don't think that extra check is appropriate though. As you say, it's
> entirely valid according to the standard, so if your application wants
> to disallow that, checking for it belongs in your application.


Yeah maybe I should inherit from string_view.


More information about the Libstdc++ mailing list