[vlc-commits] compat: fix use of <ctype.h> functions
Rémi Denis-Courmont
git at videolan.org
Mon Aug 29 18:20:34 CEST 2011
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Mon Aug 29 19:04:06 2011 +0300| [487b7594aadd2aac678fe8c75607738f43aba6aa] | committer: 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.
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=487b7594aadd2aac678fe8c75607738f43aba6aa
---
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 7ef670c..96625ca 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 e01e5c3..b3f1bfa 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 b834b48..8363598 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
More information about the vlc-commits
mailing list