[PATCH] Use strlen when searching for a nul char
Mike Frysinger
vapier@gentoo.org
Wed Apr 20 15:24:00 GMT 2016
On 20 Apr 2016 14:50, Wilco Dijkstra wrote:
> #ifndef _HAVE_STRING_ARCH_strchr
> extern void *__rawmemchr (const void *__s, int __c);
> -# define strchr(s, c) \
> +# define strchr(s, c) \
> (__extension__ (__builtin_constant_p (c) && !__builtin_constant_p (s) \
> && (c) == '\0' \
> ? (char *) __rawmemchr (s, c) \
> : __builtin_strchr (s, c)))
> #endif
>
> +#ifndef _HAVE_STRING_ARCH_rawmemchr
> +extern void *__rawmemchr (const void *__s, int __c);
> +# define __rawmemchr(s, c) \
> + (__extension__ ({ char *__s = (char *)(s); \
> + __builtin_constant_p (c) && (c) == '\0' \
> + ? (void *)(__s + strlen (__s)) \
> + : __rawmemchr (__s, (c));}))
> +# ifdef __USE_GNU
> +# define rawmemchr(s,c) __rawmemchr ((s), (c))
> +# endif
> +#endif
this relies on _HAVE_STRING_ARCH_strchr & _HAVE_STRING_ARCH_rawmemchr
being in sync in order for the strchr->strlen rewrite. should we just
do the strlen change in strchr itself too ?
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://sourceware.org/pipermail/libc-alpha/attachments/20160420/3c54fb3f/attachment.sig>
More information about the Libc-alpha
mailing list