From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2181) id C073B3857813; Tue, 10 Nov 2020 19:41:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C073B3857813 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Jonathan Wakely To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r11-4887] libstdc++: Fix more unspecified comparisons to null pointer [PR 97415] X-Act-Checkin: gcc X-Git-Author: Jonathan Wakely X-Git-Refname: refs/heads/master X-Git-Oldrev: 8b9a92f794b8ad8011e6beb11a609efa635c4600 X-Git-Newrev: ced70ebaa372945ec8d73703d81e4a10d6d51c9b Message-Id: <20201110194110.C073B3857813@sourceware.org> Date: Tue, 10 Nov 2020 19:41:10 +0000 (GMT) X-BeenThere: libstdc++-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libstdc++-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 10 Nov 2020 19:41:10 -0000 https://gcc.gnu.org/g:ced70ebaa372945ec8d73703d81e4a10d6d51c9b commit r11-4887-gced70ebaa372945ec8d73703d81e4a10d6d51c9b Author: Jonathan Wakely Date: Tue Nov 10 15:46:02 2020 +0000 libstdc++: Fix more unspecified comparisons to null pointer [PR 97415] This adds some more null checks to avoid a relational comparison with a null pointer, similar to 78198b6021a9695054dab039340202170b88423c. libstdc++-v3/ChangeLog: PR libstdc++/97415 * include/std/sstream (basic_stringbuf::_M_update_egptr) (basic_stringbuf::__xfer_bufptrs::__xfer_bufptrs): Check for null before comparing pointers. Diff: --- libstdc++-v3/include/std/sstream | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/libstdc++-v3/include/std/sstream b/libstdc++-v3/include/std/sstream index 437e2ba2a5f..9c50e4e8328 100644 --- a/libstdc++-v3/include/std/sstream +++ b/libstdc++-v3/include/std/sstream @@ -357,13 +357,16 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 void _M_update_egptr() { - const bool __testin = _M_mode & ios_base::in; - if (this->pptr() && this->pptr() > this->egptr()) + if (char_type* __pptr = this->pptr()) { - if (__testin) - this->setg(this->eback(), this->gptr(), this->pptr()); - else - this->setg(this->pptr(), this->pptr(), this->pptr()); + char_type* __egptr = this->egptr(); + if (!__egptr || __pptr > __egptr) + { + if (_M_mode & ios_base::in) + this->setg(this->eback(), this->gptr(), __pptr); + else + this->setg(__pptr, __pptr, __pptr); + } } } @@ -396,7 +399,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 _M_poff[0] = __from.pbase() - __str; _M_poff[1] = __from.pptr() - __from.pbase(); _M_poff[2] = __from.epptr() - __str; - if (__from.pptr() > __end) + if (!__end || __from.pptr() > __end) __end = __from.pptr(); }