Fix handling of return value for strcmp and strncmp

This commit is contained in:
mintsuki 2020-08-27 01:31:32 +02:00
parent fc23258aa7
commit e2a87ca33e
2 changed files with 2 additions and 2 deletions

Binary file not shown.

View File

@ -92,7 +92,7 @@ int strcmp(const char *s1, const char *s2) {
for (size_t i = 0; ; i++) {
char c1 = s1[i], c2 = s2[i];
if (c1 != c2)
return c1 - c2;
return c1 < c2 ? -1 : 1;
if (!c1)
return 0;
}
@ -102,7 +102,7 @@ int strncmp(const char *s1, const char *s2, size_t n) {
for (size_t i = 0; i < n; i++) {
char c1 = s1[i], c2 = s2[i];
if (c1 != c2)
return c1 - c2;
return c1 < c2 ? -1 : 1;
if (!c1)
return 0;
}