Author: faridz
Date: Sun Feb 19 17:34:19 2012
New Revision: 1291024
URL: http://svn.apache.org/viewvc?rev=1291024&view=rev
Log:
2012-02-19 Farid Zaripov <[email protected]>
STDCXX-1063
* include/string.cc (replace): Throw std::length_error() if __count >
max_size().
* tests/regress/21.string.replace.stdcxx-1063.cpp: New regression test
is added.
* tests/strings/21.string.replace.cpp: Added test cases to exercise
STDCXX-1063.
Added:
stdcxx/branches/4.2.x/tests/regress/21.string.replace.stdcxx-1063.cpp
(with props)
Modified:
stdcxx/branches/4.2.x/include/string.cc
stdcxx/branches/4.2.x/tests/strings/21.string.replace.cpp
Modified: stdcxx/branches/4.2.x/include/string.cc
URL:
http://svn.apache.org/viewvc/stdcxx/branches/4.2.x/include/string.cc?rev=1291024&r1=1291023&r2=1291024&view=diff
==============================================================================
--- stdcxx/branches/4.2.x/include/string.cc (original)
+++ stdcxx/branches/4.2.x/include/string.cc Sun Feb 19 17:34:19 2012
@@ -405,6 +405,12 @@ replace (size_type __pos, size_type __le
const size_type __xlen = _C_min (__size0 - __pos, __len);
+ _RWSTD_REQUIRES (__count <= max_size (),
+ (_RWSTD_ERROR_LENGTH_ERROR,
+ _RWSTD_FUNC ("basic_string::replace (size_type, "
+ "size_type, size_type, value_type)"),
+ __count, max_size ()));
+
_RWSTD_REQUIRES (__size0 - __xlen <= max_size () - __count,
(_RWSTD_ERROR_LENGTH_ERROR,
_RWSTD_FUNC ("basic_string::replace (size_type, "
Added: stdcxx/branches/4.2.x/tests/regress/21.string.replace.stdcxx-1063.cpp
URL:
http://svn.apache.org/viewvc/stdcxx/branches/4.2.x/tests/regress/21.string.replace.stdcxx-1063.cpp?rev=1291024&view=auto
==============================================================================
--- stdcxx/branches/4.2.x/tests/regress/21.string.replace.stdcxx-1063.cpp
(added)
+++ stdcxx/branches/4.2.x/tests/regress/21.string.replace.stdcxx-1063.cpp Sun
Feb 19 17:34:19 2012
@@ -0,0 +1,43 @@
+/************************************************************************
+*
+* 21.string.replace.stdcxx-1063.cpp - test case from STDCXX-1063 issue
+*
+* $Id$
+*
+***************************************************************************
+*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements. See the NOTICE file distributed
+* with this work for additional information regarding copyright
+* ownership. The ASF licenses this file to you under the Apache
+* License, Version 2.0 (the "License"); you may not use this file
+* except in compliance with the License. You may obtain a copy of
+* the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+* implied. See the License for the specific language governing
+* permissions and limitations under the License.
+*
+**************************************************************************/
+
+#include <cassert>
+#include <string>
+#include <stdexcept>
+
+int main ()
+{
+ std::string s (4095, 'a');
+
+ try {
+ s.replace (0, 1, s.max_size () + 1, 'a');
+ assert (!"Expect length error, got nothing");
+ }
+ catch (std::length_error&) {
+ }
+
+ return 0;
+}
Propchange:
stdcxx/branches/4.2.x/tests/regress/21.string.replace.stdcxx-1063.cpp
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
stdcxx/branches/4.2.x/tests/regress/21.string.replace.stdcxx-1063.cpp
------------------------------------------------------------------------------
svn:keywords = Id
Modified: stdcxx/branches/4.2.x/tests/strings/21.string.replace.cpp
URL:
http://svn.apache.org/viewvc/stdcxx/branches/4.2.x/tests/strings/21.string.replace.cpp?rev=1291024&r1=1291023&r2=1291024&view=diff
==============================================================================
--- stdcxx/branches/4.2.x/tests/strings/21.string.replace.cpp (original)
+++ stdcxx/branches/4.2.x/tests/strings/21.string.replace.cpp Sun Feb 19
17:34:19 2012
@@ -385,6 +385,9 @@ iter_iter_cptr_size_test_cases [] = {
TEST ("x@4096", 0, 4095, 0 /* self */, 4095, "x@4096", 0),
TEST ("x@4096", 0, 4095, 0 /* self */, 1, "xx", 0),
+ TEST ("ab", 0, 1, "abc", -1, "ab", 3),
+ TEST ("a@16", 0, 1, "abc", -1, "a@16", 3),
+
TEST ("last", 4, 0, "test", 4, "lasttest", 0)
};
@@ -712,6 +715,9 @@ iter_iter_size_val_test_cases [] = {
TEST ("a", 0, 1, 4095, 'x', "x@4095", 0),
+ TEST ("ab", 0, 1,-1, 'c', "ab", 3),
+ TEST ("a@16", 0, 1,-1, 'c', "a@16", 3),
+
TEST ("last", 4, 0, 4, 't', "lasttttt", 0)
};
@@ -882,7 +888,7 @@ void test_replace (charT*, Traits*, Allo
expected = exceptions [1]; // out_of_range
else if (2 == tcase.bthrow && !use_iters)
expected = exceptions [1]; // out_of_range
- else if (3 == tcase.bthrow && !use_iters)
+ else if (3 == tcase.bthrow)
expected = exceptions [2]; // length_error
else if (0 == tcase.bthrow) {
// by default excercise the exception safety of the function