This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: Patch to create builtin strncmp
- To: "Kaveh R. Ghazi" <ghazi at caip dot rutgers dot edu>
- Subject: Re: Patch to create builtin strncmp
- From: Richard Henderson <rth at cygnus dot com>
- Date: Wed, 22 Mar 2000 17:30:09 -0800
- Cc: egcs-patches at egcs dot cygnus dot com
- References: <200003230010.TAA07424@caip.rutgers.edu>
On Wed, Mar 22, 2000 at 07:10:55PM -0500, Kaveh R. Ghazi wrote:
> Er, no you don't need to know the lengths of both strings. You only
> need to know the length of *one* of them. That's how the regular
> builtin strcmp works today.
Then expand_builtin_strcmp is wrong. I don't see any wording
in md.texi that cmpstrsi must compare byte-wise and must not
read past the first mismatched byte.
Consider non-constant "hi\0" abutting a page boundary with
an unmapped page following. Compare that with the constant
"hi there". Recall that memcmp _is_ allowed to read N bytes,
and there's nothing to stop us reading 4 bytes from the first
string and faulting.
You may not even get a fault with the current compiler, but
that doesn't mean the code is correct.
r~