git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] urlmatch: use hex2chr() in append_normalized_escapes()
@ 2017-07-08  8:59 René Scharfe
  2017-07-08 14:28 ` Kyle J. McKay
  0 siblings, 1 reply; 3+ messages in thread
From: René Scharfe @ 2017-07-08  8:59 UTC (permalink / raw)
  To: Git List; +Cc: Kyle J. McKay, Junio C Hamano

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>
---
 urlmatch.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/urlmatch.c b/urlmatch.c
index 4bbde924e8..3e42bd7504 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;
 		}
-- 
2.13.2

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-07-08 15:15 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-07-08  8:59 [PATCH] urlmatch: use hex2chr() in append_normalized_escapes() René Scharfe
2017-07-08 14:28 ` Kyle J. McKay
2017-07-08 15:15   ` René Scharfe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).