From 32c7acd46401530fdbd4e98508c9baaa705f8b53 Mon Sep 17 00:00:00 2001 From: Wilco Dijkstra Date: Fri, 3 Feb 2023 12:01:33 +0000 Subject: Replace rawmemchr (s, '\0') with strchr Almost all uses of rawmemchr find the end of a string. Since most targets use a generic implementation, replacing it with strchr is better since that is optimized by compilers into strlen (s) + s. Also fix the generic rawmemchr implementation to use a cast to unsigned char in the if statement. Reviewed-by: Adhemerval Zanella --- string/rawmemchr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'string') diff --git a/string/rawmemchr.c b/string/rawmemchr.c index b44ad79859..aa8f8f2336 100644 --- a/string/rawmemchr.c +++ b/string/rawmemchr.c @@ -39,7 +39,7 @@ DIAG_IGNORE_NEEDS_COMMENT (11, "-Wstringop-overread"); void * RAWMEMCHR (const void *s, int c) { - if (c != '\0') + if ((unsigned char) c != '\0') return memchr (s, c, (size_t)-1); return (char *)s + strlen (s); } -- cgit v1.2.3