public inbox for libstdc++@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jonathan Wakely <jwakely@redhat.com>
To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org
Subject: [committed] libstdc++: Fix more unspecified comparisons to null pointer [PR 97415]
Date: Tue, 10 Nov 2020 19:41:18 +0000	[thread overview]
Message-ID: <20201110194118.GA4187555@redhat.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 386 bytes --]

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.

Tested powerpc64le-linux. Committed to trunk.


[-- Attachment #2: patch.txt --]
[-- Type: text/plain, Size: 1773 bytes --]

commit ced70ebaa372945ec8d73703d81e4a10d6d51c9b
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Tue Nov 10 15:46:02 2020

    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 --git a/libstdc++-v3/include/std/sstream b/libstdc++-v3/include/std/sstream
index 437e2ba2a5f8..9c50e4e83281 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();
 	    }
 

                 reply	other threads:[~2020-11-10 19:41 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201110194118.GA4187555@redhat.com \
    --to=jwakely@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=libstdc++@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).