X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=patch-delta.c;h=98c27beb252420102de78e50994ed5cc5b6f564a;hb=975b31dc6e12fba8f7b067ddbe32230995e05400;hp=a8d75ee1c8eab9cddcebd1e3ef5c6425e4181dbf;hpb=5569bf9bbedd63a00780fc5c110e0cfab3aa97b9;p=git.git diff --git a/patch-delta.c b/patch-delta.c index a8d75ee1..98c27beb 100644 --- a/patch-delta.c +++ b/patch-delta.c @@ -20,39 +20,24 @@ void *patch_delta(void *src_buf, unsigned long src_size, const unsigned char *data, *top; unsigned char *dst_buf, *out, cmd; unsigned long size; - int i; - /* the smallest delta size possible is 6 bytes */ - if (delta_size < 6) + if (delta_size < DELTA_SIZE_MIN) return NULL; data = delta_buf; top = delta_buf + delta_size; /* make sure the orig file size matches what we expect */ - size = i = 0; - cmd = *data++; - while (cmd) { - if (cmd & 1) - size |= *data++ << i; - i += 8; - cmd >>= 1; - } + size = get_delta_hdr_size(&data); if (size != src_size) return NULL; /* now the result size */ - size = i = 0; - cmd = *data++; - while (cmd) { - if (cmd & 1) - size |= *data++ << i; - i += 8; - cmd >>= 1; - } - dst_buf = malloc(size); + size = get_delta_hdr_size(&data); + dst_buf = malloc(size + 1); if (!dst_buf) return NULL; + dst_buf[size] = 0; out = dst_buf; while (data < top) {