From 487b7594aadd2aac678fe8c75607738f43aba6aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Denis-Courmont?= Date: Mon, 29 Aug 2011 19:04:06 +0300 Subject: [PATCH] compat: fix use of functions Unfortunately, the C standard requires an 'unsigned char' value or EOF. So we cannot blindly pass a 'char' value, which may be signed depending on the architecture. --- compat/strcasecmp.c | 7 ++++--- compat/strcasestr.c | 16 ++++++++-------- compat/strncasecmp.c | 7 ++++--- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/compat/strcasecmp.c b/compat/strcasecmp.c index 7ef670c55c..96625ca8f3 100644 --- a/compat/strcasecmp.c +++ b/compat/strcasecmp.c @@ -33,10 +33,11 @@ int strcasecmp (const char *s1, const char *s2) #else for (size_t i = 0;; i++) { - int d = tolower (s1[i]) - tolower (s2[i]); - if (d || !s1[i]) + unsigned char c1 = s1[i], c2 = s2[i]; + int d = tolower (c1) - tolower (c2); + if (d || !c1) return d; - assert (s2[i]); + assert (c2); } #endif } diff --git a/compat/strcasestr.c b/compat/strcasestr.c index e01e5c39ac..b3f1bfae08 100644 --- a/compat/strcasestr.c +++ b/compat/strcasestr.c @@ -34,17 +34,17 @@ char *strcasestr (const char *psz_big, const char *psz_little) while( *p_pos ) { - if( toupper( *p_pos ) == toupper( *psz_little ) ) + if( toupper( (unsigned char)*p_pos ) == toupper( (unsigned char)*psz_little ) ) { - char * psz_cur1 = p_pos + 1; - char * psz_cur2 = (char *)psz_little + 1; - while( *psz_cur1 && *psz_cur2 && - toupper( *psz_cur1 ) == toupper( *psz_cur2 ) ) + char *cur1 = p_pos + 1; + char *cur2 = (char *)psz_little + 1; + while( *cur1 && *cur2 + && toupper( (unsigned char)*cur1 ) == toupper( (unsigned char)*cur2 ) ) { - psz_cur1++; - psz_cur2++; + cur1++; + cur2++; } - if( !*psz_cur2 ) return p_pos; + if( !*cur2 ) return p_pos; } p_pos++; } diff --git a/compat/strncasecmp.c b/compat/strncasecmp.c index b834b4831f..8363598667 100644 --- a/compat/strncasecmp.c +++ b/compat/strncasecmp.c @@ -33,10 +33,11 @@ int strncasecmp (const char *s1, const char *s2) #else for (size_t i = 0; i < n; i++) { - int d = tolower (s1[i]) - tolower (s2[i]); - if (d || !s1[i]) + unsigned char c1 = s1[i], c2 = s2[i]; + int d = tolower (c1) - tolower (c2); + if (d || !c1) return d; - assert (s2[i]); + assert (c2); } return 0; #endif