diff mbox

[v3] PR libstdc++/68276

Message ID CAFk2RUbvMAx_95z5wGyFzN21PheLKRMHN2ia2=+7G25oPiv6nA@mail.gmail.com
State New
Headers show

Commit Message

Ville Voutilainen Dec. 18, 2015, 7:59 p.m. UTC
On 18 December 2015 at 16:47, Jonathan Wakely <jwakely@redhat.com> wrote:
> It only occurs to me now (rather than when I first suggested this
> change) that it changes behaviour for users who have replaced operator
> new, but not replaced the nothrow_t version.
>
> But I can't believe that anyone would replace operator new *just* to
> alter the behaviour of std::ios pword/iword allocation, and the
> precise form of allocation used is unspecified, so I don't think
> anyone can reasonably be hurt by this change (and it's good for
> people who want to build the library with -fno-exceptions).
>
> OK for trunk, thanks.

Here's a fix for the regression that the patch introduced. Tested with
-m32 on Linux-X64.

2015-12-18  Ville Voutilainen  <ville.voutilainen@gmail.com>

    Fix a regression introduced by the fix of libstdc++/68276.
    * src/c++11/ios.cc (_M_grow_words): Catch bad_alloc again so that
    bad_array_new_length is handled properly.

Comments

Jonathan Wakely Dec. 18, 2015, 9:20 p.m. UTC | #1
On 18/12/15 21:59 +0200, Ville Voutilainen wrote:
>Here's a fix for the regression that the patch introduced. Tested with
>-m32 on Linux-X64.

OK, thanks for the quick turnaround.
diff mbox

Patch

diff --git a/libstdc++-v3/src/c++11/ios.cc b/libstdc++-v3/src/c++11/ios.cc
index f701e61..17dad55 100644
--- a/libstdc++-v3/src/c++11/ios.cc
+++ b/libstdc++-v3/src/c++11/ios.cc
@@ -121,7 +121,13 @@  _GLIBCXX_BEGIN_NAMESPACE_VERSION
 	if (__ix < numeric_limits<int>::max())
 	  {
 	    __newsize = __ix + 1;
-	    __words = new (std::nothrow) _Words[__newsize];
+	    /* We still need to catch bad_alloc even though we use
+	       a nothrow new, because the new-expression can throw
+	       a bad_array_new_length.  */
+	    __try
+	      { __words = new (std::nothrow) _Words[__newsize]; }
+	    __catch(const std::bad_alloc&)
+	      { __words = nullptr; }
 	    if (!__words)
 	      {
 		_M_streambuf_state |= badbit;