Patch to add builtin strncmp and builtin strncpy

Kaveh R. Ghazi ghazi@caip.rutgers.edu
Sun Nov 26 12:28:00 GMT 2000


 > 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


More information about the Gcc-patches mailing list