From 6f0cb138018a2665e6fff1067ba5a29a98ec8c0c Mon Sep 17 00:00:00 2001 From: Paolo Carlini Date: Sat, 15 Jul 2006 20:30:50 +0000 Subject: [PATCH] PR libstdc++/28277 (partial: ostream bits 1) 2006-07-15 Paolo Carlini 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 | 33 ++++++++----- libstdc++-v3/include/bits/ostream.tcc | 21 +++++---- .../inserters_character/wchar_t/28277-1.cc | 46 +++++++++++++++++++ 3 files changed, 80 insertions(+), 20 deletions(-) create mode 100644 libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/28277-1.cc diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 28f13ce2d0b0..dd32bf981b11 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,17 +1,26 @@ +2006-07-15 Paolo Carlini + + 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 - * 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. diff --git a/libstdc++-v3/include/bits/ostream.tcc b/libstdc++-v3/include/bits/ostream.tcc index 7f9fbcfb0774..d53cd07579d0 100644 --- a/libstdc++-v3/include/bits/ostream.tcc +++ b/libstdc++-v3/include/bits/ostream.tcc @@ -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(__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 index 000000000000..874f15056fb3 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/28277-1.cc @@ -0,0 +1,46 @@ +// 2006-07-15 Paolo Carlini + +// 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 +#include +#include + +// 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; +}