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)
#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
}
......@@ -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++;
}
......
......@@ -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
......
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