[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:
2024-04-28 19:35:12 -07:00
parent ab84cdb790
commit 0ab2f59fe8

View File

@@ -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;