diff options
author | Ambroise Vincent <ambroise.vincent@arm.com> | 2019-06-20 10:03:17 +0100 |
---|---|---|
committer | Ambroise Vincent <ambroise.vincent@arm.com> | 2019-06-20 10:03:17 +0100 |
commit | 8051274dfc4dae689ba53bc3e56d320780cbd5a4 (patch) | |
tree | ee8e82f936f3008e99b80f97c487d369437f51f8 | |
parent | 11c53c86d4828b12ffa61ce180b0c4e694348ae3 (diff) | |
download | tf-a-tests-8051274dfc4dae689ba53bc3e56d320780cbd5a4.tar.gz |
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>
-rw-r--r-- | lib/libc/memchr.c | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/lib/libc/memchr.c b/lib/libc/memchr.c index 2eba47c95..7bd3a7e30 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++; } |