git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] urlmatch: use hex2chr() in append_normalized_escapes()

From
René Scharfe <l.s.r@web.de>
Date
Jul 8, 2017, 08:59 UTC
Message-ID
<eb5e7bb5-d0a9-c8df-e89c-a2bd2430e8b6@web.de>

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
Next: Kyle J. McKay
Message 1 of 3 in “urlmatch: use hex2chr() in append_normalized_escapes()”
  1. urlmatch: use hex2chr() in append_normalized_escapes()René Scharfe, Jul 8, 2017
  2. Kyle J. McKayJul 8, 2017
  3. René ScharfeJul 8, 2017

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.