MCPcopy Create free account
hub / github.com/git/git / decode_85

Function decode_85

base85.c:40–77  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

38}
39
40int decode_85(char *dst, const char *buffer, int len)
41{
42 prep_base85();
43
44 say2("decode 85 <%.*s>", len / 4 * 5, buffer);
45 while (len) {
46 unsigned acc = 0;
47 int de, cnt = 4;
48 unsigned char ch;
49 do {
50 ch = *buffer++;
51 de = de85[ch];
52 if (--de < 0)
53 return error("invalid base85 alphabet %c", ch);
54 acc = acc * 85 + de;
55 } while (--cnt);
56 ch = *buffer++;
57 de = de85[ch];
58 if (--de < 0)
59 return error("invalid base85 alphabet %c", ch);
60 /* Detect overflow. */
61 if (0xffffffff / 85 < acc ||
62 0xffffffff - de < (acc *= 85))
63 return error("invalid base85 sequence %.5s", buffer-5);
64 acc += de;
65 say1(" %08x", acc);
66
67 cnt = (len < 4) ? len : 4;
68 len -= cnt;
69 do {
70 acc = (acc << 8) | (acc >> 24);
71 *dst++ = acc;
72 } while (--cnt);
73 }
74 say("\n");
75
76 return 0;
77}
78
79void encode_85(char *buf, const unsigned char *data, int bytes)
80{

Callers 2

parse_binary_hunkFunction · 0.85
mainFunction · 0.85

Calls 3

prep_base85Function · 0.85
errorFunction · 0.85
sayFunction · 0.85

Tested by

no test coverage detected