libc: fix memchr implementation
authorAmbroise Vincent <ambroise.vincent@arm.com>
Fri, 7 Jun 2019 10:19:45 +0000 (11:19 +0100)
committerAmbroise Vincent <ambroise.vincent@arm.com>
Thu, 20 Jun 2019 08:59:24 +0000 (09:59 +0100)
The previous implementation could behave incorrectly because of the sign
extension of the char when compared to the int.

Change-Id: I397838b0ec87a6f1af6972d022a8c19a5184b447
Signed-off-by: Ambroise Vincent <ambroise.vincent@arm.com>
lib/libc/memchr.c

index 0fe05358bbb3f06266c87b4d488942871e8e4154..8cbb715794d1076e7f6fed9e3d4617fd7c80d892 100644 (file)
@@ -9,10 +9,10 @@
 
 void *memchr(const void *src, int c, size_t len)
 {
-       const char *s = src;
+       const unsigned char *s = src;
 
        while (len--) {
-               if (*s == c)
+               if (*s == (unsigned char)c)
                        return (void *) s;
                s++;
        }