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
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 /cache.h
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 'cache.h')
-rw-r--r--cache.h10
1 files changed, 10 insertions, 0 deletions
diff --git a/cache.h b/cache.h
index c141b3ca0d..81af2c2a6b 100644
--- a/cache.h
+++ b/cache.h
@@ -1133,6 +1133,16 @@ static inline unsigned int hexval(unsigned char c)
return hexval_table[c];
}
+/*
+ * Convert two consecutive hexadecimal digits into a char. Return a
+ * negative value on error. Don't run over the end of short strings.
+ */
+static inline int hex2chr(const char *s)
+{
+ int val = hexval(s[0]);
+ return (val < 0) ? val : (val << 4) | hexval(s[1]);
+}
+
/* Convert to/from hex/sha1 representation */
#define MINIMUM_ABBREV minimum_abbrev
#define DEFAULT_ABBREV default_abbrev