PR libstdc++/28277 (partial: ostream bits 1)
authorPaolo Carlini <paolo@gcc.gnu.org>
Sat, 15 Jul 2006 20:30:50 +0000 (20:30 +0000)
committerPaolo Carlini <paolo@gcc.gnu.org>
Sat, 15 Jul 2006 20:30:50 +0000 (20:30 +0000)
2006-07-15  Paolo Carlini  <pcarlini@suse.de>

PR libstdc++/28277 (partial: ostream bits 1)
* include/bits/ostream.tcc (operator<<(basic_ostream<_CharT>&,
const char*)): Avoid __builtin_alloca with no limit in the
widening.
* testsuite/27_io/basic_ostream/inserters_character/wchar_t/
28277-1.cc: New.

From-SVN: r115485

libstdc++-v3/ChangeLog
libstdc++-v3/include/bits/ostream.tcc
libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/28277-1.cc [new file with mode: 0644]

index 28f13ce2d0b0900706dd4d8bf5fb9c54446caaab..dd32bf981b117b61b0e0ef1e505b91254e9f577d 100644 (file)
@@ -1,17 +1,26 @@
+2006-07-15  Paolo Carlini  <pcarlini@suse.de>
+
+       PR libstdc++/28277 (partial: ostream bits 1)
+       * include/bits/ostream.tcc (operator<<(basic_ostream<_CharT>&,
+       const char*)): Avoid __builtin_alloca with no limit in the
+       widening.
+       * testsuite/27_io/basic_ostream/inserters_character/wchar_t/
+       28277-1.cc: New.
+
 2006-07-14  Benjamin Kosnik  <bkoz@redhat.com>
 
-        * acinclude.m4 (GLIBCXX_ENABLE_ATOMIC_BUILTINS): New.
-        * configure.ac: Use it.
-        * configure: Regenerated.      
-        * config.h.in: Regenerated.            
-        * configure.host: Simplify.
-        * include/bits/atomicity.h: Adjust macros.     
-        * config/cpu/generic/atomicity.h: Move...
-        * config/cpu/generic/atomicity_mutex: New.
-        * config/cpu/generic/atomicity_mutex/atomicity.h: ...here.
-        * config/cpu/generic/atomic_builtins: Rename...
-        * config/cpu/generic/atomicity_builtins: ...to this.
-        * config/cpu/generic/atomicity_builtins/atomicity.h: Moved.
+       * acinclude.m4 (GLIBCXX_ENABLE_ATOMIC_BUILTINS): New.
+       * configure.ac: Use it.
+       * configure: Regenerated.
+       * config.h.in: Regenerated.
+       * configure.host: Simplify.
+       * include/bits/atomicity.h: Adjust macros.
+       * config/cpu/generic/atomicity.h: Move...
+       * config/cpu/generic/atomicity_mutex: New.
+       * config/cpu/generic/atomicity_mutex/atomicity.h: ...here.
+       * config/cpu/generic/atomic_builtins: Rename...
+       * config/cpu/generic/atomicity_builtins: ...to this.
+       * config/cpu/generic/atomicity_builtins/atomicity.h: Moved.
        * config/cpu/mips/atomicity.h: Comment MIPS II requirement.
 
        * scripts/testsuite_flags.in: Make --cxxflags reflect CXXFLAGS.
index 7f9fbcfb077459e4f5219e72125bba8cc657c6a6..d53cd07579d00eba7c875d250655ab7f83c2d72a 100644 (file)
@@ -421,15 +421,15 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
       typename __ostream_type::sentry __cerb(__out);
       if (__cerb && __s)
        {
-         size_t __clen = __traits_type::length(__s);
-         _CharT* __ws = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT)
-                                                              * __clen));
-         for (size_t  __i = 0; __i < __clen; ++__i)
-           __ws[__i] = __out.widen(__s[__i]);
-         _CharT* __str = __ws;
-
+         _CharT* __ws = 0;
          try
            {
+             const size_t __clen = __traits_type::length(__s);
+             __ws = new _CharT[__clen];
+             for (size_t  __i = 0; __i < __clen; ++__i)
+               __ws[__i] = __out.widen(__s[__i]);
+             _CharT* __str = __ws;
+             
              const streamsize __w = __out.width();
              streamsize __len = static_cast<streamsize>(__clen);
              if (__w > __len)
@@ -444,9 +444,14 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
                }
              __out._M_write(__str, __len);
              __out.width(0);
+
+             delete [] __ws;
            }
          catch(...)
-           { __out._M_setstate(ios_base::badbit); }
+           {
+             delete [] __ws;
+             __out._M_setstate(ios_base::badbit);
+           }
        }
       else if (!__s)
        __out.setstate(ios_base::badbit);
diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/28277-1.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/28277-1.cc
new file mode 100644 (file)
index 0000000..874f150
--- /dev/null
@@ -0,0 +1,46 @@
+// 2006-07-15  Paolo Carlini  <pcarlini@suse.de>
+
+// Copyright (C) 2006 Free Software Foundation
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING.  If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 27.6.2.5.4 basic_ostream character inserters
+
+#include <ostream>
+#include <sstream>
+#include <testsuite_hooks.h>
+
+// libstdc++/28277
+void test01()
+{
+  using namespace std;
+  bool test __attribute__((unused)) = true;
+
+  wostringstream oss_01;
+  const string str_01(5000000, 'a');
+
+  oss_01 << str_01.c_str();
+
+  VERIFY( oss_01.good() );
+  VERIFY( oss_01.str().size() == str_01.size() );
+}
+
+int main()
+{
+  test01();
+  return 0;
+}