MCPcopy Index your code
hub / github.com/git/git / patch_delta

Function patch_delta

patch-delta.c:15–94  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

13#include "delta.h"
14
15void *patch_delta(const void *src_buf, size_t src_size,
16 const void *delta_buf, size_t delta_size,
17 size_t *dst_size)
18{
19 const unsigned char *data, *top;
20 unsigned char *dst_buf, *out, cmd;
21 size_t size;
22
23 if (delta_size < DELTA_SIZE_MIN)
24 return NULL;
25
26 data = delta_buf;
27 top = (const unsigned char *) delta_buf + delta_size;
28
29 /* make sure the orig file size matches what we expect */
30 size = get_delta_hdr_size(&data, top);
31 if (size != src_size)
32 return NULL;
33
34 /* now the result size */
35 size = get_delta_hdr_size(&data, top);
36 dst_buf = xmallocz(size);
37
38 out = dst_buf;
39 while (data < top) {
40 cmd = *data++;
41 if (cmd & 0x80) {
42 unsigned long cp_off = 0, cp_size = 0;
43#define PARSE_CP_PARAM(bit, var, shift) do { \
44 if (cmd & (bit)) { \
45 if (data >= top) \
46 goto bad_length; \
47 var |= ((unsigned) *data++ << (shift)); \
48 } } while (0)
49 PARSE_CP_PARAM(0x01, cp_off, 0);
50 PARSE_CP_PARAM(0x02, cp_off, 8);
51 PARSE_CP_PARAM(0x04, cp_off, 16);
52 PARSE_CP_PARAM(0x08, cp_off, 24);
53 PARSE_CP_PARAM(0x10, cp_size, 0);
54 PARSE_CP_PARAM(0x20, cp_size, 8);
55 PARSE_CP_PARAM(0x40, cp_size, 16);
56#undef PARSE_CP_PARAM
57 if (cp_size == 0) cp_size = 0x10000;
58 if (unsigned_add_overflows(cp_off, cp_size) ||
59 cp_off + cp_size > src_size ||
60 cp_size > size)
61 goto bad_length;
62 memcpy(out, (char *) src_buf + cp_off, cp_size);
63 out += cp_size;
64 size -= cp_size;
65 } else if (cmd) {
66 if (cmd > size || cmd > top - data)
67 goto bad_length;
68 memcpy(out, data, cmd);
69 out += cmd;
70 data += cmd;
71 size -= cmd;
72 } else {

Callers 6

unpack_entryFunction · 0.85
apply_binary_fragmentFunction · 0.85
cmd__deltaFunction · 0.85
get_base_dataFunction · 0.85
resolve_deltaFunction · 0.85
resolve_deltaFunction · 0.85

Calls 3

get_delta_hdr_sizeFunction · 0.85
xmalloczFunction · 0.85
errorFunction · 0.85

Tested by 1

cmd__deltaFunction · 0.68