From: René Scharfe Date: Sat, 8 Jul 2017 08:59:19 +0000 (+0200) Subject: urlmatch: use hex2chr() in append_normalized_escapes() X-Git-Tag: v2.14.0-rc0~11^2 X-Git-Url: http://git.neil.brown.name/?a=commitdiff_plain;h=50533135622a80b0326c7e93067e136072bef5eb;p=git.git urlmatch: use hex2chr() in append_normalized_escapes() Simplify the code by using hex2chr() to convert and check for invalid characters at the same time instead of doing that sequentially with one table lookup for each. Signed-off-by: Rene Scharfe Signed-off-by: Junio C Hamano --- diff --git a/urlmatch.c b/urlmatch.c index 4bbde924e..3e42bd750 100644 --- a/urlmatch.c +++ b/urlmatch.c @@ -42,12 +42,12 @@ static int append_normalized_escapes(struct strbuf *buf, from_len--; if (ch == '%') { - if (from_len < 2 || - !isxdigit(from[0]) || - !isxdigit(from[1])) + if (from_len < 2) return 0; - ch = hexval(*from++) << 4; - ch |= hexval(*from++); + ch = hex2chr(from); + if (ch < 0) + return 0; + from += 2; from_len -= 2; was_esc = 1; }