From ce3f6dc655392803a59c9b2f2ec9509fd8061b33 Mon Sep 17 00:00:00 2001 From: Nicolas Pitre Date: Mon, 20 Oct 2008 16:46:19 -0400 Subject: fix multiple issues in index-pack Since commit 9441b61dc5, two issues affected correct behavior of index-pack: 1) The real_type of a delta object is the 'real_type' of its base, not the 'type' which can be a "delta type". Consequence of this is a corrupted pack index file which only needs to be recreated with a good index-pack command ('git verify-pack' will flag those). 2) The code sequence: result->data = patch_delta(get_base_data(base), base->obj->size, delta_data, delta_size, &result->size); has two issues of its own since base->obj->size should instead be base->size as we want the size of the actual object data and not the size of the delta object it is represented by. Except that simply replacing base->obj->size with base->size won't make the code more correct as the C language doesn't enforce a particular ordering for the evaluation of needed arguments for a function call, hence base->size could be pushed on the stack before get_base_data() which initializes base->size is called. Signed-off-by: Nicolas Pitre Tested-by: Jeff King Signed-off-by: Junio C Hamano --- index-pack.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'index-pack.c') diff --git a/index-pack.c b/index-pack.c index 9def64133e..f109a00270 100644 --- a/index-pack.c +++ b/index-pack.c @@ -514,15 +514,14 @@ static void *get_base_data(struct base_data *c) static void resolve_delta(struct object_entry *delta_obj, struct base_data *base, struct base_data *result) { - void *delta_data; - unsigned long delta_size; + void *base_data, *delta_data; - delta_obj->real_type = base->obj->type; + delta_obj->real_type = base->obj->real_type; delta_data = get_data_from_pack(delta_obj); - delta_size = delta_obj->size; + base_data = get_base_data(base); result->obj = delta_obj; - result->data = patch_delta(get_base_data(base), base->obj->size, - delta_data, delta_size, &result->size); + result->data = patch_delta(base_data, base->size, + delta_data, delta_obj->size, &result->size); free(delta_data); if (!result->data) bad_object(delta_obj->idx.offset, "failed to apply delta"); -- cgit v1.2.1