scc

simple C compiler
git clone git://git.2f30.org/scc
Log | Files | Refs | README | LICENSE

commit 07e85cd0473b47634b6e0166939d719116ef0680
parent 22e17d14116ca2b13ea849f2f568c417d8143888
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Fri, 17 Feb 2017 12:11:21 +0100

[libc] Fix strcmp() and strcoll()

If we want to support character encoding differents of ascii
we must to cast the operands to unsigned before doing the
substraction, or otherwise we can have wrong values.

Diffstat:
Mlibc/src/strcmp.c | 2+-
Mlibc/src/strcoll.c | 2+-
2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/libc/src/strcmp.c b/libc/src/strcmp.c @@ -7,5 +7,5 @@ strcmp(const char *s1, const char *s2) { while (*s1 && *s2 && *s1 != *s2) ++s1, ++s2; - return *s1 - *s2; + return *(unsigned char *)s1 - *(unsigned char *)s2; } diff --git a/libc/src/strcoll.c b/libc/src/strcoll.c @@ -7,5 +7,5 @@ strcoll(const char *s1, const char *s2) { while (*s1 && *s2 && *s1 != *s2) ++s1, ++s2; - return *s1 - *s2; + return *(unsigned char *) s1 - *(unsigned char *) s2; }