]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
valgrind's strcmp() implementation (to clients) treats char as signed
authorJulian Seward <jseward@acm.org>
Thu, 5 Sep 2002 20:02:40 +0000 (20:02 +0000)
committerJulian Seward <jseward@acm.org>
Thu, 5 Sep 2002 20:02:40 +0000 (20:02 +0000)
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

vg_clientfuncs.c

index 026b99b5766f0f516c104ee88f213b03adf9dc69..2a2740446ecd17d0d4f472cc96588498e9ef9daf 100644 (file)
@@ -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;
 }