]> git.neil.brown.name Git - git.git/commitdiff
urlmatch: use hex2chr() in append_normalized_escapes()
authorRené Scharfe <l.s.r@web.de>
Sat, 8 Jul 2017 08:59:19 +0000 (10:59 +0200)
committerJunio C Hamano <gitster@pobox.com>
Sun, 9 Jul 2017 16:43:01 +0000 (09:43 -0700)
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 <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
urlmatch.c

index 4bbde924e8bf7e73f4f696d0319235ec56263a8f..3e42bd750485d67bb6151ab5f15ac09a0d887502 100644 (file)
@@ -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;
                }