The standard doesn't guarantee that null pointers compare less than
non-null pointers. AddressSanitizer complains about the pptr()> egptr()
comparison in basic_stringbuf::str() when egptr() is null.
libstdc++-v3/ChangeLog:
PR libstdc++/97415
* include/std/sstream (basic_stringbuf::str()): Check for
null egptr() before comparing to non-null pptr().
str() const
{
__string_type __ret(_M_string.get_allocator());
- if (this->pptr())
+ if (char_type* __pptr = this->pptr())
{
+ char_type* __egptr = this->egptr();
// The current egptr() may not be the actual string end.
- if (this->pptr() > this->egptr())
- __ret.assign(this->pbase(), this->pptr());
+ if (!__egptr || __pptr > __egptr)
+ __ret.assign(this->pbase(), __pptr);
else
- __ret.assign(this->pbase(), this->egptr());
+ __ret.assign(this->pbase(), __egptr);
}
else
__ret = _M_string;