public inbox for gcc-patches@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: [patch] Fix dangling pointer in future_error::what()
Date: Fri, 06 Mar 2015 12:31:00 -0000	[thread overview]
Message-ID: <20150306123153.GL8789@redhat.com> (raw)

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

This bug didn't show up with COW strings, but is a real problem with
the new std::string. The fix is to call error_code::message() early
and store the result in the logic_error base class during
construction.

Tested x86_64-linux, committed to trunk.

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

commit 3f7252dcc10eba698c12460c0a74bd313c7fef01
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Fri Mar 6 11:04:13 2015 +0000

    	* include/std/future (future_error(error_code)): Construct base
    	class with error_code's message.
    	* src/c++11/future.cc (future_error::what()): Do not call c_str() on
    	temporary string.

diff --git a/libstdc++-v3/include/std/future b/libstdc++-v3/include/std/future
index cb0226d..fc3f816 100644
--- a/libstdc++-v3/include/std/future
+++ b/libstdc++-v3/include/std/future
@@ -98,7 +98,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
   public:
     explicit future_error(error_code __ec)
-    : logic_error("std::future_error"), _M_code(__ec)
+    : logic_error("std::future_error: " + __ec.message()), _M_code(__ec)
     { }
 
     virtual ~future_error() noexcept;
diff --git a/libstdc++-v3/src/c++11/future.cc b/libstdc++-v3/src/c++11/future.cc
index c711a5f..3cf503b 100644
--- a/libstdc++-v3/src/c++11/future.cc
+++ b/libstdc++-v3/src/c++11/future.cc
@@ -75,7 +75,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   future_error::~future_error() noexcept { }
 
   const char*
-  future_error::what() const noexcept { return _M_code.message().c_str(); }
+  future_error::what() const noexcept { return logic_error::what(); }
 
 #if defined(_GLIBCXX_HAS_GTHREADS) && defined(_GLIBCXX_USE_C99_STDINT_TR1) \
   && (ATOMIC_INT_LOCK_FREE > 1)

                 reply	other threads:[~2015-03-06 12:31 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=20150306123153.GL8789@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).