This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Patch to add builtin strncmp and builtin strncpy


"Kaveh R. Ghazi" <ghazi@caip.rutgers.edu> writes:

> This patch adds builtins for strncpy and strncmp as described on the
> GCC projects page.  The transformations done are:
> 
> strncpy(s1, s2, 0) -> NOP
>   (handling side-effects of s1 & s2)
> 
> strncpy(s1, "string", n) -> memcpy (s1, "string", n)
>   (where strlen("string")+1 >= n)

Why not also

strncpy(s1, "string", n) -> memcpy (s1, "string", sizeof ("string")+1)
   (where strlen("string")+1 < n)

?

-- 
- Geoffrey Keating <geoffk@geoffk.org>

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]