Bug 21646 - Fix a signed char comparison
authorColin Walters <walters@verbum.org>
Fri, 10 Jul 2009 23:26:52 +0000 (19:26 -0400)
committerColin Walters <walters@verbum.org>
Tue, 14 Jul 2009 19:39:40 +0000 (15:39 -0400)
Original suggested patch from Marc-Andre Lureau <marcandre.lureau@gmail.com>

Explicitly cast to unsigned char before we do comparisons.
(cherry picked from commit 1f6ac4deef91df3130c61525a2800e6b8a0ddcbf)

dbus/dbus-sysdeps-util-unix.c

index d31e144..5353bd7 100644 (file)
@@ -1148,10 +1148,13 @@ string_squash_nonprintable (DBusString *str)
   len = _dbus_string_get_length (str);
   
   for (i = 0; i < len; i++)
-    if (buf[i] == '\0')
-      buf[i] = ' ';
-    else if (buf[i] < 0x20 || buf[i] > 127)
-      buf[i] = '?';
+    {
+         unsigned char c = (unsigned char) buf[i];
+      if (c == '\0')
+        c = ' ';
+      else if (c < 0x20 || c > 127)
+        c = '?';
+    }
 }
 
 /**