From: Julian Seward Date: Thu, 5 Sep 2002 20:02:40 +0000 (+0000) Subject: valgrind's strcmp() implementation (to clients) treats char as signed X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8ac2922f9ae003492f556740d7c761fc5af81a3f;p=thirdparty%2Fvalgrind.git valgrind's strcmp() implementation (to clients) treats char as signed whereas the libc implementation it replaces treats char as unsigned. Fix! God knows how anything much ever worked before now. MERGE TO ERASER git-svn-id: svn://svn.valgrind.org/valgrind/branches/VALGRIND_1_0_BRANCH@900 --- diff --git a/vg_clientfuncs.c b/vg_clientfuncs.c index 026b99b576..2a2740446e 100644 --- a/vg_clientfuncs.c +++ b/vg_clientfuncs.c @@ -442,7 +442,8 @@ char* strcpy ( char* dest, const char* src ) return dest_orig; } -int strncmp ( const char* s1, const char* s2, unsigned int nmax ) +int strncmp ( const unsigned char* s1, const unsigned char* s2, + unsigned int nmax ) { unsigned int n = 0; while (True) { @@ -451,8 +452,8 @@ int strncmp ( const char* s1, const char* s2, unsigned int nmax ) if (*s1 == 0) return -1; if (*s2 == 0) return 1; - if (*(UChar*)s1 < *(UChar*)s2) return -1; - if (*(UChar*)s1 > *(UChar*)s2) return 1; + if (*(unsigned char*)s1 < *(unsigned char*)s2) return -1; + if (*(unsigned char*)s1 > *(unsigned char*)s2) return 1; s1++; s2++; n++; } @@ -460,16 +461,17 @@ int strncmp ( const char* s1, const char* s2, unsigned int nmax ) int strcmp ( const char* s1, const char* s2 ) { - register char c1, c2; + register unsigned char c1; + register unsigned char c2; while (True) { - c1 = *s1; - c2 = *s2; + c1 = *(unsigned char *)s1; + c2 = *(unsigned char *)s2; if (c1 != c2) break; if (c1 == 0) break; s1++; s2++; } - if (c1 < c2) return -1; - if (c1 > c2) return 1; + if ((unsigned char)c1 < (unsigned char)c2) return -1; + if ((unsigned char)c1 > (unsigned char)c2) return 1; return 0; }