isxdigit: cast input to unsigned char
authorJeff King <peff@peff.net>
Wed, 15 Oct 2014 22:34:05 +0000 (18:34 -0400)
committerJunio C Hamano <gitster@pobox.com>
Thu, 16 Oct 2014 17:10:36 +0000 (10:10 -0700)
Otherwise, callers must do so or risk triggering warnings
-Wchar-subscript (and rightfully so; a signed char might
cause us to use a bogus negative index into the
hexval_table).

While we are dropping the now-unnecessary casts from the
caller in urlmatch.c, we can get rid of similar casts in
actually parsing the hex by using the hexval() helper, which
implicitly casts to unsigned (but note that we cannot
implement isxdigit in terms of hexval(), as it also casts
its return value to unsigned).

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
git-compat-util.h
urlmatch.c
index fb41118c0705c628bed093c4a915a58aa01a5a1a..44890d5b18f1f37308bdf77c80ee66bb65afc913 100644 (file)
@@ -677,7 +677,7 @@ extern const unsigned char sane_ctype[256];
 #define iscntrl(x) (sane_istest(x,GIT_CNTRL))
 #define ispunct(x) sane_istest(x, GIT_PUNCT | GIT_REGEX_SPECIAL | \
                GIT_GLOB_SPECIAL | GIT_PATHSPEC_MAGIC)
-#define isxdigit(x) (hexval_table[x] != -1)
+#define isxdigit(x) (hexval_table[(unsigned char)(x)] != -1)
 #define tolower(x) sane_case((unsigned char)(x), 0x20)
 #define toupper(x) sane_case((unsigned char)(x), 0)
 #define is_pathspec_magic(x) sane_istest(x,GIT_PATHSPEC_MAGIC)
index 3d4c54b5cd5d6f6cb4e0ea97550799eb9d46f033..618d2164919758b141aa9d6408c57a4fb99c922c 100644 (file)
@@ -43,11 +43,11 @@ static int append_normalized_escapes(struct strbuf *buf,
                from_len--;
                if (ch == '%') {
                        if (from_len < 2 ||
-                           !isxdigit((unsigned char)from[0]) ||
-                           !isxdigit((unsigned char)from[1]))
+                           !isxdigit(from[0]) ||
+                           !isxdigit(from[1]))
                                return 0;
-                       ch = hexval_table[(unsigned char)*from++] << 4;
-                       ch |= hexval_table[(unsigned char)*from++];
+                       ch = hexval(*from++) << 4;
+                       ch |= hexval(*from++);
                        from_len -= 2;
                        was_esc = 1;
                }