The C spec requires that the comarison be done in terms of unsigned char. The code style in this file is terrible, but does claim to be Xen BSD style, so fix up these functions while rewriting them.
Signed-off-by: Andrew Cooper <[email protected]> --- CC: Jan Beulich <[email protected]> CC: Wei Liu <[email protected]> CC: Roger Pau Monné <[email protected]> --- xen/common/string.c | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/xen/common/string.c b/xen/common/string.c index 1e122ab..24491bd 100644 --- a/xen/common/string.c +++ b/xen/common/string.c @@ -119,14 +119,16 @@ EXPORT_SYMBOL(strlcat); */ int (strcmp)(const char *cs, const char *ct) { - register signed char __res; + for ( ; ; ) + { + unsigned char c1 = *cs++, c2 = *ct++; - while (1) { - if ((__res = *cs - *ct++) != 0 || !*cs++) - break; - } + if ( c1 != c2 ) + return c1 - c2; - return __res; + if ( c1 == '\0' ) + return 0; + } } #endif @@ -139,15 +141,18 @@ int (strcmp)(const char *cs, const char *ct) */ int (strncmp)(const char *cs, const char *ct, size_t count) { - register signed char __res = 0; + for ( ; count; count-- ) + { + unsigned char c1 = *cs++, c2 = *ct++; - while (count) { - if ((__res = *cs - *ct++) != 0 || !*cs++) - break; - count--; - } + if ( c1 != c2 ) + return c1 - c2; + + if ( c1 == '\0' ) + break; + } - return __res; + return 0; } #endif -- 2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
