Skip to content

Commit 0bf46af

Browse files
committed
Merge branch 'jc/fix-alloc-sortbuf-in-index-pack'
A hotfix for what is in 2.5-rc but not in 2.4. * jc/fix-alloc-sortbuf-in-index-pack: index-pack: fix allocation of sorted_by_pos array
2 parents 5bdb7a7 + 781d930 commit 0bf46af

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

builtin/index-pack.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1227,7 +1227,7 @@ static void resolve_deltas(void)
12271227
* - append objects to convert thin pack to full pack if required
12281228
* - write the final 20-byte SHA-1
12291229
*/
1230-
static void fix_unresolved_deltas(struct sha1file *f, int nr_unresolved);
1230+
static void fix_unresolved_deltas(struct sha1file *f);
12311231
static void conclude_pack(int fix_thin_pack, const char *curr_pack, unsigned char *pack_sha1)
12321232
{
12331233
if (nr_ref_deltas + nr_ofs_deltas == nr_resolved_deltas) {
@@ -1249,7 +1249,7 @@ static void conclude_pack(int fix_thin_pack, const char *curr_pack, unsigned cha
12491249
memset(objects + nr_objects + 1, 0,
12501250
nr_unresolved * sizeof(*objects));
12511251
f = sha1fd(output_fd, curr_pack);
1252-
fix_unresolved_deltas(f, nr_unresolved);
1252+
fix_unresolved_deltas(f);
12531253
strbuf_addf(&msg, _("completed with %d local objects"),
12541254
nr_objects - nr_objects_initial);
12551255
stop_progress_msg(&progress, msg.buf);
@@ -1331,10 +1331,10 @@ static int delta_pos_compare(const void *_a, const void *_b)
13311331
return a->obj_no - b->obj_no;
13321332
}
13331333

1334-
static void fix_unresolved_deltas(struct sha1file *f, int nr_unresolved)
1334+
static void fix_unresolved_deltas(struct sha1file *f)
13351335
{
13361336
struct ref_delta_entry **sorted_by_pos;
1337-
int i, n = 0;
1337+
int i;
13381338

13391339
/*
13401340
* Since many unresolved deltas may well be themselves base objects
@@ -1346,12 +1346,12 @@ static void fix_unresolved_deltas(struct sha1file *f, int nr_unresolved)
13461346
* before deltas depending on them, a good heuristic is to start
13471347
* resolving deltas in the same order as their position in the pack.
13481348
*/
1349-
sorted_by_pos = xmalloc(nr_unresolved * sizeof(*sorted_by_pos));
1349+
sorted_by_pos = xmalloc(nr_ref_deltas * sizeof(*sorted_by_pos));
13501350
for (i = 0; i < nr_ref_deltas; i++)
1351-
sorted_by_pos[n++] = &ref_deltas[i];
1352-
qsort(sorted_by_pos, n, sizeof(*sorted_by_pos), delta_pos_compare);
1351+
sorted_by_pos[i] = &ref_deltas[i];
1352+
qsort(sorted_by_pos, nr_ref_deltas, sizeof(*sorted_by_pos), delta_pos_compare);
13531353

1354-
for (i = 0; i < n; i++) {
1354+
for (i = 0; i < nr_ref_deltas; i++) {
13551355
struct ref_delta_entry *d = sorted_by_pos[i];
13561356
enum object_type type;
13571357
struct base_data *base_obj = alloc_base_data();

0 commit comments

Comments
 (0)