aboutsummaryrefslogtreecommitdiff
path: root/pretty.c
diff options
context:
space:
mode:
authorRené Scharfe <l.s.r@web.de>2016-09-03 17:59:20 +0200
committerJunio C Hamano <gitster@pobox.com>2016-09-07 10:42:46 -0700
commitd23309733a5b2a9e1adc304ee50c5a5ed7a087c2 (patch)
treec1555e8fce5bdf708b48fb43391c98002dcd3716 /pretty.c
parente0c1ceafc5bece92d35773a75fff59497e1d9bd5 (diff)
downloadgit-d23309733a5b2a9e1adc304ee50c5a5ed7a087c2.tar.gz
git-d23309733a5b2a9e1adc304ee50c5a5ed7a087c2.tar.xz
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 'pretty.c')
-rw-r--r--pretty.c13
1 files changed, 5 insertions, 8 deletions
diff --git a/pretty.c b/pretty.c
index b27165603..37e74cbb8 100644
--- a/pretty.c
+++ b/pretty.c
@@ -1063,7 +1063,7 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */
const struct commit *commit = c->commit;
const char *msg = c->message;
struct commit_list *p;
- int h1, h2;
+ int ch;
/* these are independent of the commit */
switch (placeholder[0]) {
@@ -1087,14 +1087,11 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */
return 1;
case 'x':
/* %x00 == NUL, %x0a == LF, etc. */
- if (0 <= (h1 = hexval_table[0xff & placeholder[1]]) &&
- h1 <= 16 &&
- 0 <= (h2 = hexval_table[0xff & placeholder[2]]) &&
- h2 <= 16) {
- strbuf_addch(sb, (h1<<4)|h2);
- return 3;
- } else
+ ch = hex2chr(placeholder + 1);
+ if (ch < 0)
return 0;
+ strbuf_addch(sb, ch);
+ return 3;
case 'w':
if (placeholder[1] == '(') {
unsigned long width = 0, indent1 = 0, indent2 = 0;