cast ctype(3) function/macro arguments from char to unsigned char
authorTodd C. Miller <Todd.Miller@courtesan.com>
Wed, 28 Mar 2012 17:07:54 +0000 (13:07 -0400)
committerTodd C. Miller <Todd.Miller@courtesan.com>
Wed, 28 Mar 2012 17:07:54 +0000 (13:07 -0400)
to avoid potential negative subscripting.

compat/fnmatch.c

index 1daaba2d008beceea7c1dc0ca3ae0c5259ae5110..54a31421338e7976c01850512f4dde9f7b317353 100644 (file)
@@ -208,10 +208,11 @@ leadingclosebrace:
                 /* XXX: handle locale/MBCS comparison, advance by MBCS char width */
                 if ((**string >= *startch) && (**string <= **pattern))
                     result = 0;
-                else if (nocase && (isupper(**string) || isupper(*startch)
-                                                      || isupper(**pattern))
-                            && (tolower(**string) >= tolower(*startch)) 
-                            && (tolower(**string) <= tolower(**pattern)))
+                else if (nocase && (isupper((unsigned char)**string) ||
+                                   isupper((unsigned char)*startch) ||
+                                   isupper((unsigned char)**pattern))
+                            && (tolower((unsigned char)**string) >= tolower((unsigned char)*startch)) 
+                            && (tolower((unsigned char)**string) <= tolower((unsigned char)**pattern)))
                     result = 0;
 
                 ++*pattern;
@@ -221,8 +222,9 @@ leadingclosebrace:
             /* XXX: handle locale/MBCS comparison, advance by MBCS char width */
             if ((**string == **pattern))
                 result = 0;
-            else if (nocase && (isupper(**string) || isupper(**pattern))
-                            && (tolower(**string) == tolower(**pattern)))
+            else if (nocase && (isupper((unsigned char)**string) ||
+                               isupper((unsigned char)**pattern))
+                            && (tolower((unsigned char)**string) == tolower((unsigned char)**pattern)))
                 result = 0;
 
             ++*pattern;
@@ -248,8 +250,8 @@ leadingclosebrace:
     /* XXX: handle locale/MBCS comparison, advance by the MBCS char width */
     if (**string == **pattern)
         result = 0;
-    else if (nocase && (isupper(**string) || isupper(**pattern))
-                    && (tolower(**string) == tolower(**pattern)))
+    else if (nocase && (isupper((unsigned char)**string) || isupper((unsigned char)**pattern))
+                    && (tolower((unsigned char)**string) == tolower((unsigned char)**pattern)))
         result = 0;
 
     /* Refuse to advance over trailing slash or nulls