Browse Source

string: fix a couple minor issues in strncmp()

Alex Lyon 7 years ago
parent
commit
cfc1014c6e
2 changed files with 1 additions and 3 deletions
  1. 1 1
      src/string/src/lib.rs
  2. 0 2
      tests/string/strncmp.c

+ 1 - 1
src/string/src/lib.rs

@@ -161,7 +161,7 @@ pub unsafe extern "C" fn strncmp(s1: *const c_char, s2: *const c_char, n: usize)
 
     for (&a, &b) in s1.iter().zip(s2.iter()) {
         let val = (a as c_int) - (b as c_int);
-        if val != 0 || a == 0 {
+        if a != b || a == 0 {
             return val;
         }
     }

+ 0 - 2
tests/string/strncmp.c

@@ -9,7 +9,5 @@ int main(int argc, char* argv[]) {
     printf("%d\n", strncmp("a", "c", 1));
     printf("%d\n", strncmp("a", "a", 2));
 
-    puts("test");
-
     return 0;
 }