diff --git a/patch-delta.c b/patch-delta.c
index a8d75ee1c8eab9cddcebd1e3ef5c6425e4181dbf..98c27beb252420102de78e50994ed5cc5b6f564a 100644 (file)
--- a/patch-delta.c
+++ b/patch-delta.c
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) {