Commit 487b7594 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

compat: fix use of <ctype.h> 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.
parent 2e171403
...@@ -33,10 +33,11 @@ int strcasecmp (const char *s1, const char *s2) ...@@ -33,10 +33,11 @@ int strcasecmp (const char *s1, const char *s2)
#else #else
for (size_t i = 0;; i++) for (size_t i = 0;; i++)
{ {
int d = tolower (s1[i]) - tolower (s2[i]); unsigned char c1 = s1[i], c2 = s2[i];
if (d || !s1[i]) int d = tolower (c1) - tolower (c2);
if (d || !c1)
return d; return d;
assert (s2[i]); assert (c2);
} }
#endif #endif
} }
...@@ -34,17 +34,17 @@ char *strcasestr (const char *psz_big, const char *psz_little) ...@@ -34,17 +34,17 @@ char *strcasestr (const char *psz_big, const char *psz_little)
while( *p_pos ) 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 *cur1 = p_pos + 1;
char * psz_cur2 = (char *)psz_little + 1; char *cur2 = (char *)psz_little + 1;
while( *psz_cur1 && *psz_cur2 && while( *cur1 && *cur2
toupper( *psz_cur1 ) == toupper( *psz_cur2 ) ) && toupper( (unsigned char)*cur1 ) == toupper( (unsigned char)*cur2 ) )
{ {
psz_cur1++; cur1++;
psz_cur2++; cur2++;
} }
if( !*psz_cur2 ) return p_pos; if( !*cur2 ) return p_pos;
} }
p_pos++; p_pos++;
} }
......
...@@ -33,10 +33,11 @@ int strncasecmp (const char *s1, const char *s2) ...@@ -33,10 +33,11 @@ int strncasecmp (const char *s1, const char *s2)
#else #else
for (size_t i = 0; i < n; i++) for (size_t i = 0; i < n; i++)
{ {
int d = tolower (s1[i]) - tolower (s2[i]); unsigned char c1 = s1[i], c2 = s2[i];
if (d || !s1[i]) int d = tolower (c1) - tolower (c2);
if (d || !c1)
return d; return d;
assert (s2[i]); assert (c2);
} }
return 0; return 0;
#endif #endif
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment