summaryrefslogtreecommitdiff
path: root/ref-filter.c
diff options
context:
space:
mode:
authorRené Scharfe <l.s.r@web.de>2016-09-03 15:59:20 (GMT)
committerJunio C Hamano <gitster@pobox.com>2016-09-07 17:42:46 (GMT)
commitd23309733a5b2a9e1adc304ee50c5a5ed7a087c2 (patch)
treec1555e8fce5bdf708b48fb43391c98002dcd3716 /ref-filter.c
parente0c1ceafc5bece92d35773a75fff59497e1d9bd5 (diff)
downloadgit-d23309733a5b2a9e1adc304ee50c5a5ed7a087c2.zip
git-d23309733a5b2a9e1adc304ee50c5a5ed7a087c2.tar.gz
git-d23309733a5b2a9e1adc304ee50c5a5ed7a087c2.tar.bz2
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 'ref-filter.c')
-rw-r--r--ref-filter.c20
1 files changed, 1 insertions, 19 deletions
diff --git a/ref-filter.c b/ref-filter.c
index bc551a7..9adbb8a 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -1576,24 +1576,6 @@ void ref_array_sort(struct ref_sorting *sorting, struct ref_array *array)
qsort(array->items, array->nr, sizeof(struct ref_array_item *), compare_refs);
}
-static int hex1(char ch)
-{
- if ('0' <= ch && ch <= '9')
- return ch - '0';
- else if ('a' <= ch && ch <= 'f')
- return ch - 'a' + 10;
- else if ('A' <= ch && ch <= 'F')
- return ch - 'A' + 10;
- return -1;
-}
-static int hex2(const char *cp)
-{
- if (cp[0] && cp[1])
- return (hex1(cp[0]) << 4) | hex1(cp[1]);
- else
- return -1;
-}
-
static void append_literal(const char *cp, const char *ep, struct ref_formatting_state *state)
{
struct strbuf *s = &state->stack->output;
@@ -1603,7 +1585,7 @@ static void append_literal(const char *cp, const char *ep, struct ref_formatting
if (cp[1] == '%')
cp++;
else {
- int ch = hex2(cp + 1);
+ int ch = hex2chr(cp + 1);
if (0 <= ch) {
strbuf_addch(s, ch);
cp += 3;