[hackers] [scc] [libc] Fix strcmp() and strcoll() || Roberto E. Vargas Caballero

From: <git_AT_suckless.org>
Date: Fri, 17 Feb 2017 12:16:10 +0100 (CET)

commit 07e85cd0473b47634b6e0166939d719116ef0680
Author: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
AuthorDate: Fri Feb 17 12:11:21 2017 +0100
Commit: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
CommitDate: Fri Feb 17 12:11:21 2017 +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.

diff --git a/libc/src/strcmp.c b/libc/src/strcmp.c
index 56ab3a4..dae93fc 100644
--- a/libc/src/strcmp.c
+++ b/libc/src/strcmp.c
_AT_@ -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
index d914f5e..edd6840 100644
--- a/libc/src/strcoll.c
+++ b/libc/src/strcoll.c
_AT_@ -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;
 }
Received on Fri Feb 17 2017 - 12:16:10 CET

This archive was generated by hypermail 2.3.0 : Fri Feb 17 2017 - 12:24:19 CET