Coverage Report

Created: 2024-09-16 06:12

/src/git/hex-ll.c
Line
Count
Source (jump to first uncovered line)
1
#include "git-compat-util.h"
2
#include "hex-ll.h"
3
4
const signed char hexval_table[256] = {
5
   -1, -1, -1, -1, -1, -1, -1, -1,    /* 00-07 */
6
   -1, -1, -1, -1, -1, -1, -1, -1,    /* 08-0f */
7
   -1, -1, -1, -1, -1, -1, -1, -1,    /* 10-17 */
8
   -1, -1, -1, -1, -1, -1, -1, -1,    /* 18-1f */
9
   -1, -1, -1, -1, -1, -1, -1, -1,    /* 20-27 */
10
   -1, -1, -1, -1, -1, -1, -1, -1,    /* 28-2f */
11
    0,  1,  2,  3,  4,  5,  6,  7,    /* 30-37 */
12
    8,  9, -1, -1, -1, -1, -1, -1,    /* 38-3f */
13
   -1, 10, 11, 12, 13, 14, 15, -1,    /* 40-47 */
14
   -1, -1, -1, -1, -1, -1, -1, -1,    /* 48-4f */
15
   -1, -1, -1, -1, -1, -1, -1, -1,    /* 50-57 */
16
   -1, -1, -1, -1, -1, -1, -1, -1,    /* 58-5f */
17
   -1, 10, 11, 12, 13, 14, 15, -1,    /* 60-67 */
18
   -1, -1, -1, -1, -1, -1, -1, -1,    /* 68-67 */
19
   -1, -1, -1, -1, -1, -1, -1, -1,    /* 70-77 */
20
   -1, -1, -1, -1, -1, -1, -1, -1,    /* 78-7f */
21
   -1, -1, -1, -1, -1, -1, -1, -1,    /* 80-87 */
22
   -1, -1, -1, -1, -1, -1, -1, -1,    /* 88-8f */
23
   -1, -1, -1, -1, -1, -1, -1, -1,    /* 90-97 */
24
   -1, -1, -1, -1, -1, -1, -1, -1,    /* 98-9f */
25
   -1, -1, -1, -1, -1, -1, -1, -1,    /* a0-a7 */
26
   -1, -1, -1, -1, -1, -1, -1, -1,    /* a8-af */
27
   -1, -1, -1, -1, -1, -1, -1, -1,    /* b0-b7 */
28
   -1, -1, -1, -1, -1, -1, -1, -1,    /* b8-bf */
29
   -1, -1, -1, -1, -1, -1, -1, -1,    /* c0-c7 */
30
   -1, -1, -1, -1, -1, -1, -1, -1,    /* c8-cf */
31
   -1, -1, -1, -1, -1, -1, -1, -1,    /* d0-d7 */
32
   -1, -1, -1, -1, -1, -1, -1, -1,    /* d8-df */
33
   -1, -1, -1, -1, -1, -1, -1, -1,    /* e0-e7 */
34
   -1, -1, -1, -1, -1, -1, -1, -1,    /* e8-ef */
35
   -1, -1, -1, -1, -1, -1, -1, -1,    /* f0-f7 */
36
   -1, -1, -1, -1, -1, -1, -1, -1,    /* f8-ff */
37
};
38
39
int hex_to_bytes(unsigned char *binary, const char *hex, size_t len)
40
9.51k
{
41
190k
  for (; len; len--, hex += 2) {
42
180k
    unsigned int val = (hexval(hex[0]) << 4) | hexval(hex[1]);
43
44
180k
    if (val & ~0xff)
45
0
      return -1;
46
180k
    *binary++ = val;
47
180k
  }
48
9.51k
  return 0;
49
9.51k
}