* [committed] libstdc++: Fix unspecified comparison to null pointer [PR 97415]
@ 2020-10-14 19:21 Jonathan Wakely
0 siblings, 0 replies; only message in thread
From: Jonathan Wakely @ 2020-10-14 19:21 UTC (permalink / raw)
To: libstdc++, gcc-patches; +Cc: Thomas Rodgers
[-- Attachment #1: Type: text/plain, Size: 404 bytes --]
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().
Tested powerpc64le-linux. Committed to trunk.
[-- Attachment #2: patch.txt --]
[-- Type: text/plain, Size: 1434 bytes --]
commit 78198b6021a9695054dab039340202170b88423c
Author: Jonathan Wakely <jwakely@redhat.com>
Date: Wed Oct 14 18:55:14 2020
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().
diff --git a/libstdc++-v3/include/std/sstream b/libstdc++-v3/include/std/sstream
index 9cca54d17d1..06960e30bf2 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;
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2020-10-14 19:21 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-14 19:21 [committed] libstdc++: Fix unspecified comparison to null pointer [PR 97415] Jonathan Wakely
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).