Skip to content

Commit 50a7177

Browse files
peffgitster
authored andcommitted
isxdigit: cast input to unsigned char
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent fe1b226 commit 50a7177

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

git-compat-util.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,7 @@ extern const unsigned char sane_ctype[256];
677677
#define iscntrl(x) (sane_istest(x,GIT_CNTRL))
678678
#define ispunct(x) sane_istest(x, GIT_PUNCT | GIT_REGEX_SPECIAL | \
679679
GIT_GLOB_SPECIAL | GIT_PATHSPEC_MAGIC)
680-
#define isxdigit(x) (hexval_table[x] != -1)
680+
#define isxdigit(x) (hexval_table[(unsigned char)(x)] != -1)
681681
#define tolower(x) sane_case((unsigned char)(x), 0x20)
682682
#define toupper(x) sane_case((unsigned char)(x), 0)
683683
#define is_pathspec_magic(x) sane_istest(x,GIT_PATHSPEC_MAGIC)

urlmatch.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ static int append_normalized_escapes(struct strbuf *buf,
4343
from_len--;
4444
if (ch == '%') {
4545
if (from_len < 2 ||
46-
!isxdigit((unsigned char)from[0]) ||
47-
!isxdigit((unsigned char)from[1]))
46+
!isxdigit(from[0]) ||
47+
!isxdigit(from[1]))
4848
return 0;
49-
ch = hexval_table[(unsigned char)*from++] << 4;
50-
ch |= hexval_table[(unsigned char)*from++];
49+
ch = hexval(*from++) << 4;
50+
ch |= hexval(*from++);
5151
from_len -= 2;
5252
was_esc = 1;
5353
}

0 commit comments

Comments
 (0)