From: Paolo Carlini Date: Tue, 29 Oct 2002 08:08:40 +0000 (+0100) Subject: re PR libstdc++/8347 (empty vector range used in string construction causes core... X-Git-Tag: releases/gcc-3.2.1~90 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=931e1c9f5b5236af76986ca93a37948fd22760d5;p=thirdparty%2Fgcc.git re PR libstdc++/8347 (empty vector range used in string construction causes core dump.) 2002-10-29 Paolo Carlini PR libstdc++/8347 * include/bits/basic_string.tcc (string::_S_construct(_InIter, _InIter, const _Alloc&, forward_iterator_tag)): Do not throw logic error if __beg == NULL && __end == __beg. (string::string(const _CharT*, const _Alloc&)): Tweak. * testsuite/21_strings/ctor_copy_dtor.cc: Add test05 from PR. From-SVN: r58610 --- diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 435d90c4e3f1..eba309c0da58 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,13 @@ +2002-10-29 Paolo Carlini + + PR libstdc++/8347 + * include/bits/basic_string.tcc + (string::_S_construct(_InIter, _InIter, const _Alloc&, + forward_iterator_tag)): Do not throw logic error if + __beg == NULL && __end == __beg. + (string::string(const _CharT*, const _Alloc&)): Tweak. + * testsuite/21_strings/ctor_copy_dtor.cc: Add test05 from PR. + 2002-10-23 Jakub Jelinek * testsuite/22_locale/num_put_members_char.cc (test01): Swap size diff --git a/libstdc++-v3/include/bits/basic_string.tcc b/libstdc++-v3/include/bits/basic_string.tcc index 6d646ad2a105..322528c90aa2 100644 --- a/libstdc++-v3/include/bits/basic_string.tcc +++ b/libstdc++-v3/include/bits/basic_string.tcc @@ -139,13 +139,13 @@ namespace std { size_type __dnew = static_cast(distance(__beg, __end)); + if (__beg == __end && __a == _Alloc()) + return _S_empty_rep()._M_refcopy(); + // NB: Not required, but considered best practice. if (__builtin_expect(__beg == _InIter(), 0)) __throw_logic_error("attempt to create string with null pointer"); - if (__beg == __end && __a == _Alloc()) - return _S_empty_rep()._M_refcopy(); - // Check for out_of_range and length_error exceptions. _Rep* __r = _Rep::_S_create(__dnew, __a); try @@ -223,8 +223,8 @@ namespace std template basic_string<_CharT, _Traits, _Alloc>:: basic_string(const _CharT* __s, const _Alloc& __a) - : _M_dataplus(_S_construct(__s, __s ? __s + traits_type::length(__s) : 0, - __a), __a) + : _M_dataplus(_S_construct(__s, __s ? __s + traits_type::length(__s) : + __s + npos, __a), __a) { } template diff --git a/libstdc++-v3/testsuite/21_strings/ctor_copy_dtor.cc b/libstdc++-v3/testsuite/21_strings/ctor_copy_dtor.cc index ea22cfc2aa2f..63c8be429940 100644 --- a/libstdc++-v3/testsuite/21_strings/ctor_copy_dtor.cc +++ b/libstdc++-v3/testsuite/21_strings/ctor_copy_dtor.cc @@ -22,6 +22,7 @@ #include #include +#include #include #include @@ -214,6 +215,15 @@ void test04() VERIFY( str02 == "onifotrop" ); } +// libstdc++/8347 +void test05() +{ + bool test = true; + + std::vector empty; + std::string empty2(empty.begin(), empty.end()); +} + int main() { __set_testsuite_memlimit(); @@ -221,5 +231,6 @@ int main() test02(); test03(); test04(); + test05(); return 0; }