ref: 8cfd34400a006cb6bca88595ce93ece172aadad4
parent: a62afbe74e2be29ed8b697a4094c5778cddfa09e
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Fri Feb 17 07:11:21 EST 2017
[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.
--- a/libc/src/strcmp.c
+++ b/libc/src/strcmp.c
@@ -7,5 +7,5 @@
{
while (*s1 && *s2 && *s1 != *s2)
++s1, ++s2;
- return *s1 - *s2;
+ return *(unsigned char *)s1 - *(unsigned char *)s2;
}
--- a/libc/src/strcoll.c
+++ b/libc/src/strcoll.c
@@ -7,5 +7,5 @@
{
while (*s1 && *s2 && *s1 != *s2)
++s1, ++s2;
- return *s1 - *s2;
+ return *(unsigned char *) s1 - *(unsigned char *) s2;
}