xen/lib: Fix strcmp() and strncmp()

The C standard requires that each character be compared as unsigned
char. Xen's current behaviour compares as signed char, which changes
the answer when chars with a value greater than 0x7f are used.

Suggested-by: Andrew Cooper <andrew.cooper3@citrix.com>
Signed-off-by: Jane Malalane <jane.malalane@citrix.com>
Reviewed-by: Ian Jackson <iwj@xenproject.org>
This commit is contained in:
Jane Malalane authored and Ian Jackson committed 2021-07-30 10:52:46 +01:00
1 parent 58ad654ebc
commit 3747a2bb67
2 files changed
+10 -6

No files matched your search

+5 -3
View File
@@ -11,14 +11,16 @@
*/
int (strcmp)(const char *cs, const char *ct)
{
register signed char __res;
unsigned char *csu = (unsigned char *)cs;
unsigned char *ctu = (unsigned char *)ct;
int res;
while (1) {
if ((__res = *cs - *ct++) != 0 || !*cs++)
if ((res = *csu - *ctu++) != 0 || !*csu++)
break;
}
return __res;
return res;
}
/*
+5 -3
View File
@@ -12,15 +12,17 @@
*/
int (strncmp)(const char *cs, const char *ct, size_t count)
{
register signed char __res = 0;
unsigned char *csu = (unsigned char *)cs;
unsigned char *ctu = (unsigned char *)ct;
int res = 0;
while (count) {
if ((__res = *cs - *ct++) != 0 || !*cs++)
if ((res = *csu - *ctu++) != 0 || !*csu++)
break;
count--;
}
return __res;
return res;
}
/*
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.