Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/url.c
diff options
context:
space:
mode:
authorRené Scharfe <l.s.r@web.de>2016-09-03 18:59:20 +0300
committerJunio C Hamano <gitster@pobox.com>2016-09-07 20:42:46 +0300
commitd23309733a5b2a9e1adc304ee50c5a5ed7a087c2 (patch)
treec1555e8fce5bdf708b48fb43391c98002dcd3716 /url.c
parente0c1ceafc5bece92d35773a75fff59497e1d9bd5 (diff)
introduce hex2chr() for converting two hexadecimal digits to a character
Add and use a helper function that decodes the char value of two hexadecimal digits. It returns a negative number on error, avoids running over the end of the given string and doesn't shift negative values. Signed-off-by: Rene Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'url.c')
-rw-r--r--url.c21
1 files changed, 1 insertions, 20 deletions
diff --git a/url.c b/url.c
index 2d89ad190c..eaf4f07081 100644
--- a/url.c
+++ b/url.c
@@ -29,25 +29,6 @@ int is_url(const char *url)
return (url[0] == ':' && url[1] == '/' && url[2] == '/');
}
-static int url_decode_char(const char *q)
-{
- int i;
- unsigned char val = 0;
- for (i = 0; i < 2; i++) {
- unsigned char c = *q++;
- val <<= 4;
- if (c >= '0' && c <= '9')
- val += c - '0';
- else if (c >= 'a' && c <= 'f')
- val += c - 'a' + 10;
- else if (c >= 'A' && c <= 'F')
- val += c - 'A' + 10;
- else
- return -1;
- }
- return val;
-}
-
static char *url_decode_internal(const char **query, int len,
const char *stop_at, struct strbuf *out,
int decode_plus)
@@ -66,7 +47,7 @@ static char *url_decode_internal(const char **query, int len,
}
if (c == '%') {
- int val = url_decode_char(q + 1);
+ int val = hex2chr(q + 1);
if (0 <= val) {
strbuf_addch(out, val);
q += 3;