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