mirror of
https://github.com/justinian/jsix.git
synced 2025-12-10 00:14:32 -08:00
[libc] Fix a strncmp bug
The strncmp implementation too eagerly advanced the string pointers, such that it would compare the next characters after the ones that didn't match.
This commit is contained in:
@@ -16,7 +16,9 @@ int strncmp(const char *s1, const char *s2, size_t n) {
|
|||||||
char const * c1 = s1;
|
char const * c1 = s1;
|
||||||
char const * c2 = s2;
|
char const * c2 = s2;
|
||||||
|
|
||||||
while (n && *c1 && *c2 && *c1++ == *c2++) n--;
|
while (n && *c1 && *c2 && *c1 == *c2) {
|
||||||
|
n--; c1++; c2++;
|
||||||
|
}
|
||||||
|
|
||||||
if (!n || *c1 == *c2) return 0;
|
if (!n || *c1 == *c2) return 0;
|
||||||
if (!*c2 || *c1 > *c2) return 1;
|
if (!*c2 || *c1 > *c2) return 1;
|
||||||
|
|||||||
Reference in New Issue
Block a user