basic_string.tcc (find(const _CharT*, size_type, size_type)): Robustify.

2006-09-05  Paolo Carlini  <pcarlini@suse.de>

	* include/bits/basic_string.tcc (find(const _CharT*, size_type,
	size_type)): Robustify.
	* include/ext/vstring.tcc (find(const _CharT*, size_type,
	size_type)): Likewise.

From-SVN: r116700
This commit is contained in:
Paolo Carlini 2006-09-05 17:38:44 +00:00 committed by Paolo Carlini
parent 9a7fd67a82
commit 5527be59f4
3 changed files with 23 additions and 8 deletions

View File

@ -1,3 +1,10 @@
2006-09-05 Paolo Carlini <pcarlini@suse.de>
* include/bits/basic_string.tcc (find(const _CharT*, size_type,
size_type)): Robustify.
* include/ext/vstring.tcc (find(const _CharT*, size_type,
size_type)): Likewise.
2006-09-05 Paolo Carlini <pcarlini@suse.de>
* include/bits/basic_string.tcc (find(const _CharT*, size_type,

View File

@ -716,10 +716,14 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
if (__n == 0)
return __pos <= __size ? __pos : npos;
for (; __pos + __n <= __size; ++__pos)
if (traits_type::eq(__data[__pos], __s[0])
&& traits_type::compare(__data + __pos + 1, __s + 1, __n - 1) == 0)
return __pos;
if (__n <= __size)
{
for (; __pos + __n <= __size; ++__pos)
if (traits_type::eq(__data[__pos], __s[0])
&& traits_type::compare(__data + __pos + 1,
__s + 1, __n - 1) == 0)
return __pos;
}
return npos;
}

View File

@ -277,10 +277,14 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
if (__n == 0)
return __pos <= __size ? __pos : npos;
for (; __pos + __n <= __size; ++__pos)
if (traits_type::eq(__data[__pos], __s[0])
&& traits_type::compare(__data + __pos + 1, __s + 1, __n - 1) == 0)
return __pos;
if (__n <= __size)
{
for (; __pos + __n <= __size; ++__pos)
if (traits_type::eq(__data[__pos], __s[0])
&& traits_type::compare(__data + __pos + 1,
__s + 1, __n - 1) == 0)
return __pos;
}
return npos;
}