This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: [Patch] To string::find
- From: Paolo Carlini <pcarlini at suse dot de>
- To: Paolo Carlini <pcarlini at suse dot de>
- Cc: libstdc++ <libstdc++ at gcc dot gnu dot org>
- Date: Tue, 05 Sep 2006 19:42:10 +0200
- Subject: Re: [Patch] To string::find
- References: <44FC9AEE.5030408@suse.de>
Paolo Carlini wrote:
Tomorrow I'd like to go ahead...
I'm also applying the below, which robustifies the code wrt arithmetic
overflows (note, beyond the existing string::find). After the release of
4.2.0 we can consider further improving the performance (there are
various options).
Paolo.
///////////////////
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.
Index: include/ext/vstring.tcc
===================================================================
--- include/ext/vstring.tcc (revision 116698)
+++ include/ext/vstring.tcc (working copy)
@@ -277,10 +277,14 @@
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;
}
Index: include/bits/basic_string.tcc
===================================================================
--- include/bits/basic_string.tcc (revision 116698)
+++ include/bits/basic_string.tcc (working copy)
@@ -716,10 +716,14 @@
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;
}