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: "Kaveh R. Ghazi" <ghazi at caip dot rutgers dot edu>
- Subject: Re: Patch to add builtin strncmp and builtin strncpy
- From: Geoff Keating <geoffk at geoffk dot org>
- Date: 26 Nov 2000 13:15:44 -0800
- CC: gcc-patches at gcc dot gnu dot org
- References: <200011261918.OAA07147@caip.rutgers.edu>
"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>