libc: fix memchr implementation
The previous implementation could behave incorrectly because of the sign
extension of the char when compared to the int.
Change-Id: Id1e40ca9cfb1c271cb391e26698862726b833c8b
Signed-off-by: Ambroise Vincent <ambroise.vincent@arm.com>
diff --git a/lib/libc/memchr.c b/lib/libc/memchr.c
index 2eba47c..7bd3a7e 100644
--- a/lib/libc/memchr.c
+++ b/lib/libc/memchr.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2013-2018, ARM Limited and Contributors. All rights reserved.
+ * Copyright (c) 2013-2019, ARM Limited and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
@@ -8,10 +8,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++;
}