diff options
author | Paolo Carlini <paolo@gcc.gnu.org> | 2006-07-15 20:30:50 +0000 |
---|---|---|
committer | Paolo Carlini <paolo@gcc.gnu.org> | 2006-07-15 20:30:50 +0000 |
commit | 6f0cb138018a2665e6fff1067ba5a29a98ec8c0c (patch) | |
tree | 65ba10596ac222fd1caa9cee446e3f94d5b4755e /libstdc++-v3 | |
parent | b0d5d5de789ef8cb4df99c08c3bf864152e65e75 (diff) | |
download | gcc-6f0cb138018a2665e6fff1067ba5a29a98ec8c0c.zip gcc-6f0cb138018a2665e6fff1067ba5a29a98ec8c0c.tar.gz gcc-6f0cb138018a2665e6fff1067ba5a29a98ec8c0c.tar.bz2 |
PR libstdc++/28277 (partial: ostream bits 1)
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
Diffstat (limited to 'libstdc++-v3')
-rw-r--r-- | libstdc++-v3/ChangeLog | 33 | ||||
-rw-r--r-- | libstdc++-v3/include/bits/ostream.tcc | 21 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/28277-1.cc | 46 |
3 files changed, 80 insertions, 20 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 28f13ce..dd32bf9 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -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. diff --git a/libstdc++-v3/include/bits/ostream.tcc b/libstdc++-v3/include/bits/ostream.tcc index 7f9fbcf..d53cd07 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<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 index 0000000..874f150 --- /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 <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; +} |