Fix issues in some ARM compilers, due to char being unsigned?
authorGuy Harris <guy@alum.mit.edu>
Thu, 16 Oct 2014 18:06:06 +0000 (11:06 -0700)
committerGuy Harris <guy@alum.mit.edu>
Thu, 16 Oct 2014 18:06:38 +0000 (18:06 +0000)
I'm not 100% certain the comparisons were right even with signed char;
make the comparisons unsigned vs. unsigned, regardless of whether char
is signed or not.  (No, C doesn't require it to be signed; that's why
there's a "signed" keyword.)

Change-Id: Icbbd1019a2f7d4ebb40d821255834f825cd7c5a7
Reviewed-on: https://code.wireshark.org/review/4731
Reviewed-by: Guy Harris <guy@alum.mit.edu>
epan/ftypes/ftype-pcre.c

index e9e42681d6857946d2172e6fd8476d95e3e151ee..693ea884230abc88c9b9a2eea7b6e739322cec52 100644 (file)
@@ -50,18 +50,27 @@ static gboolean
 raw_flag_needed(const gchar *pattern)
 {
     gboolean found = FALSE;
-    const gchar *s = pattern;
+    /*
+     * gchar is neither guaranteed to be signed nor guaranteed to be
+     * unsigned.  Make s point to guint8, and use regular hex constants,
+     * to make sure the comparisons are unsigned vs. unsigned (on at
+     * least one ARM version of gcc, with char being unsigned, the
+     * comparisons before those changes warned about always being
+     * true due to the limited range of the data type).
+     */
+    const guint8 *s;
     size_t i, len;
 
     /* find any character whose hex value is two letters */
-    len = strlen(s);
+    len = strlen(pattern);
+    s = (const guint8 *)pattern;
     for (i = 0; i < len; i++) {
-        if ((s[i] >= '\xAA' && s[i] <= '\xAF') ||
-            (s[i] >= '\xBA' && s[i] <= '\xBF') ||
-            (s[i] >= '\xCA' && s[i] <= '\xCF') ||
-            (s[i] >= '\xDA' && s[i] <= '\xDF') ||
-            (s[i] >= '\xEA' && s[i] <= '\xEF') ||
-            (s[i] >= '\xFA' && s[i] <= '\xFF'))
+        if ((s[i] >= 0xAA && s[i] <= 0xAF) ||
+            (s[i] >= 0xBA && s[i] <= 0xBF) ||
+            (s[i] >= 0xCA && s[i] <= 0xCF) ||
+            (s[i] >= 0xDA && s[i] <= 0xDF) ||
+            (s[i] >= 0xEA && s[i] <= 0xEF) ||
+            (s[i] >= 0xFA && s[i] <= 0xFF))
         {
             found = TRUE;
             break;