This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: Patch to add builtin strncmp and builtin strncpy
- To: jsm28 at cam dot ac dot uk
- Subject: Re: Patch to add builtin strncmp and builtin strncpy
- From: "Kaveh R. Ghazi" <ghazi at caip dot rutgers dot edu>
- Date: Sun, 26 Nov 2000 15:28:03 -0500 (EST)
- Cc: gcc-patches at gcc dot gnu dot org
> From: "Joseph S. Myers" <jsm28@cam.ac.uk>
>
> On Sun, 26 Nov 2000, Kaveh R. Ghazi wrote:
>
> > strncmp(s1, "string", n) -> strcmp(s1, "string")
> > strncmp("string", s2, n) -> strcmp("string", s2)
> > (where strlen("string") < n)
>
> As noted on the web page, the C standard requires arguments to strcmp, but
> not to strncmp, to be null-terminated. If an implementation is found that
> reads beyond the expected point in the non-constant string in strcmp, this
> will need to be dealt with.
Sigh, I suppose it would be considered "legal" for the strcmp
implementation to call strlen on each arg before doing any
comparisons. That would barf if s1 wasn't null terminated in the
original call to strncmp. Perhaps that particular transformation
isn't valid, now I'm not sure.
>
> The builtins need to be added to the lists in extend.texi.
Yup. Will do.
--
Kaveh R. Ghazi Engagement Manager / Project Services
ghazi@caip.rutgers.edu Qwest Internet Solutions