Skip to content

Commit 1732f24

Browse files
committed
fixed strncmp.
1 parent 60360ae commit 1732f24

File tree

1 file changed

+2
-10
lines changed

1 file changed

+2
-10
lines changed

kernel/string.c

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -106,17 +106,9 @@ int strncmp(const char *s1, const char *s2, size_t n)
106106
int diff = 0;
107107

108108
while (n > 0) {
109-
if (!s1) {
110-
diff = 0 - (int)*s2;
111-
} else if (!s2) {
112-
diff = (int)*s1;
113-
} else {
114-
diff = (int)*s1 - (int)*s2;
115-
}
116-
117-
if (diff)
109+
diff = (unsigned char)*s1 - (unsigned char)*s2;
110+
if (diff || !*s1)
118111
break;
119-
120112
s1++;
121113
s2++;
122114
n--;

0 commit comments

Comments
 (0)