index-pack: always zero-initialize object_entry list
authorJeff King <peff@peff.net>
Tue, 19 Mar 2013 16:17:22 +0000 (12:17 -0400)
committerJunio C Hamano <gitster@pobox.com>
Wed, 20 Mar 2013 19:53:26 +0000 (12:53 -0700)
Commit 38a4556 (index-pack: start learning to emulate
"verify-pack -v", 2011-06-03) added a "delta_depth" counter
to each "struct object_entry". Initially, all object entries
have their depth set to 0; in resolve_delta, we then set the
depth of each delta to "base + 1". Base entries never have
their depth touched, and remain at 0.

To ensure that all depths start at 0, that commit changed
calls to xmalloc the object_entry list into calls to
xcalloc. However, it forgot that we grow the list with
xrealloc later. These extra entries are used when we add an
object from elsewhere to complete a thin pack. If we add a
non-delta object, its depth value will just be uninitialized
heap data.

This patch fixes it by zero-initializing entries we add to
the objects list via the xrealloc.

Signed-off-by: Jeff King <peff@peff.net>
Acked-by: Thomas Rast <trast@student.ethz.ch>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/index-pack.c
index 953dd3004e285ce7aa0432f4fe0eacb0d0c2c887..6922086376839e85ce43a5334ba67e18bb6f4c04 100644 (file)
@@ -1106,6 +1106,8 @@ static void conclude_pack(int fix_thin_pack, const char *curr_pack, unsigned cha
                objects = xrealloc(objects,
                                   (nr_objects + nr_unresolved + 1)
                                   * sizeof(*objects));
                objects = xrealloc(objects,
                                   (nr_objects + nr_unresolved + 1)
                                   * sizeof(*objects));
+               memset(objects + nr_objects + 1, 0,
+                      nr_unresolved * sizeof(*objects));
                f = sha1fd(output_fd, curr_pack);
                fix_unresolved_deltas(f, nr_unresolved);
                sprintf(msg, "completed with %d local objects",
                f = sha1fd(output_fd, curr_pack);
                fix_unresolved_deltas(f, nr_unresolved);
                sprintf(msg, "completed with %d local objects",