mirror of
https://github.com/xen-project/xen.git
synced 2026-10-28 10:11:27 +01:00
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:
1 parent
58ad654ebc
commit
3747a2bb67
2 files changed
+10
-6
No files matched your search
+5
-3
@@ -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
@@ -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;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||