diff options
author | Jonathan Wakely <jwakely@redhat.com> | 2020-10-14 18:55:14 +0100 |
---|---|---|
committer | Jonathan Wakely <jwakely@redhat.com> | 2020-10-14 18:55:14 +0100 |
commit | 78198b6021a9695054dab039340202170b88423c (patch) | |
tree | 26c5ba105ab29254b95c361a5c65b2f431003836 | |
parent | 5b00bcc5432dc494c70f85ee717e4ecc47e7fcae (diff) | |
download | gcc-78198b6021a9695054dab039340202170b88423c.zip gcc-78198b6021a9695054dab039340202170b88423c.tar.gz gcc-78198b6021a9695054dab039340202170b88423c.tar.bz2 |
libstdc++: Fix unspecified comparison to null pointer [PR 97415]
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().
-rw-r--r-- | libstdc++-v3/include/std/sstream | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/libstdc++-v3/include/std/sstream b/libstdc++-v3/include/std/sstream index 9cca54d..06960e3 100644 --- a/libstdc++-v3/include/std/sstream +++ b/libstdc++-v3/include/std/sstream @@ -178,13 +178,14 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 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; |