basic_string.h (replace(__pos, __n1, __s, __n2): Fix and tighten __throw_length_error check.
2002-04-26 Paolo Carlini <pcarlini@unitus.it> * include/bits/basic_string.h (replace(__pos, __n1, __s, __n2): Fix and tighten __throw_length_error check. * testsuite/21_strings/replace.cc (test05): New. * testsuite/21_strings/replace.cc (test02, test03, test04): Tweak. From-SVN: r52797
This commit is contained in:
parent
bde3c0c07d
commit
adf2e3e668
@ -1,3 +1,10 @@
|
||||
2002-04-26 Paolo Carlini <pcarlini@unitus.it>
|
||||
|
||||
* include/bits/basic_string.h (replace(__pos, __n1, __s, __n2):
|
||||
Fix and tighten __throw_length_error check.
|
||||
* testsuite/21_strings/replace.cc (test05): New.
|
||||
* testsuite/21_strings/replace.cc (test02, test03, test04): Tweak.
|
||||
|
||||
2002-04-23 Loren J. Rittle <ljrittle@acm.org>
|
||||
|
||||
* include/std/std_fstream.h (basic_filebuf::sync): Hoist
|
||||
|
@ -642,10 +642,10 @@ namespace std
|
||||
const size_type __size = this->size();
|
||||
if (__pos > __size)
|
||||
__throw_out_of_range("basic_string::replace");
|
||||
if (__size - __n1 > this->max_size() - __n2)
|
||||
__throw_length_error("basic_string::replace");
|
||||
const bool __testn1 = __n1 < __size - __pos;
|
||||
const size_type __foldn1 = __testn1 ? __n1 : __size - __pos;
|
||||
if (__size - __foldn1 > this->max_size() - __n2)
|
||||
__throw_length_error("basic_string::replace");
|
||||
if (_M_rep()->_M_is_shared() || less<const _CharT*>()(__s, _M_data())
|
||||
|| less<const _CharT*>()(_M_data() + __size, __s))
|
||||
return _M_replace_safe(_M_ibegin() + __pos,
|
||||
|
@ -84,6 +84,7 @@ bool test01(void)
|
||||
void
|
||||
test02()
|
||||
{
|
||||
bool test = true;
|
||||
const char* strlit = "../the long pier/Hanalei Bay/Kauai/Hawaii";
|
||||
std::string aux = strlit;
|
||||
aux.replace(aux.begin()+5, aux.begin()+20,
|
||||
@ -100,6 +101,7 @@ test02()
|
||||
void
|
||||
test03()
|
||||
{
|
||||
bool test = true;
|
||||
const char* title01 = "nine types of ambiguity";
|
||||
const char* title02 = "ultra";
|
||||
std::string str01 = title01;
|
||||
@ -145,6 +147,7 @@ test03()
|
||||
void
|
||||
test04()
|
||||
{
|
||||
bool test = true;
|
||||
std::string str01 = "geogaddi";
|
||||
std::string str02;
|
||||
|
||||
@ -175,11 +178,25 @@ test04()
|
||||
VERIFY(str02 == "geogaddi");
|
||||
}
|
||||
|
||||
// We wrongly used __n1 instead of __foldn1 in the length_error
|
||||
// check at the beginning of replace(__pos, __n1, __s, __n2)
|
||||
void
|
||||
test05()
|
||||
{
|
||||
bool test = true;
|
||||
std::string str01 = "londinium";
|
||||
std::string str02 = "cydonia";
|
||||
|
||||
str01.replace(0, 20, str02.c_str(), 3);
|
||||
VERIFY(str01 == "cyd");
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
test01();
|
||||
test02();
|
||||
test03();
|
||||
test04();
|
||||
test05();
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user