midx.c: store `nr`, `alloc` variables as `size_t`'s

In the `write_midx_context` structure, we use two `uint32_t`'s to track the length and allocated size of the packs, and one `uint32_t` to track the number of objects in the MIDX. In practice, having these be 32-bit unsigned values shouldn't cause any problems since we are unlikely to have that many objects or packs in any real-world repository. But these values should be `size_t`'s, so change their type to reflect that. Signed-off-by: Taylor Blau <me@ttaylorr.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Taylor Blau committed Jul 12, 2023 at 19:37 UTC cc38127439be50ade60fb2db18c7f5f0cc170a36
1 file changed +9 -7
midx.c
+9 -7
@@ -446,14 +446,14 @@ static int idx_or_pack_name_cmp(const void *_va, const void *_vb)
446
447 struct write_midx_context {
448 struct pack_info *info;
449 - uint32_t nr;
450 - uint32_t alloc;
449 + size_t nr;
450 + size_t alloc;
451 struct multi_pack_index *m;
452 struct progress *progress;
453 unsigned pack_paths_checked;
454
455 struct pack_midx_entry *entries;
456 - uint32_t entries_nr;
456 + size_t entries_nr;
457
458 uint32_t *pack_perm;
459 uint32_t *pack_order;
@@ -671,17 +671,18 @@ static void midx_fanout_add_pack_fanout(struct midx_fanout *fanout,
671 static struct pack_midx_entry *get_sorted_entries(struct multi_pack_index *m,
672 struct pack_info *info,
673 uint32_t nr_packs,
674 - uint32_t *nr_objects,
674 + size_t *nr_objects,
675 int preferred_pack)
676 {
677 uint32_t cur_fanout, cur_pack, cur_object;
678 - uint32_t alloc_objects, total_objects = 0;
678 + size_t alloc_objects, total_objects = 0;
679 struct midx_fanout fanout = { 0 };
680 struct pack_midx_entry *deduplicated_entries = NULL;
681 uint32_t start_pack = m ? m->num_packs : 0;
682
683 for (cur_pack = start_pack; cur_pack < nr_packs; cur_pack++)
684 - total_objects += info[cur_pack].p->num_objects;
684 + total_objects = st_add(total_objects,
685 + info[cur_pack].p->num_objects);
686
687 /*
688 * As we de-duplicate by fanout value, we expect the fanout
@@ -724,7 +725,8 @@ static struct pack_midx_entry *get_sorted_entries(struct multi_pack_index *m,
725 &fanout.entries[cur_object].oid))
726 continue;
727
727 - ALLOC_GROW(deduplicated_entries, *nr_objects + 1, alloc_objects);
728 + ALLOC_GROW(deduplicated_entries, st_add(*nr_objects, 1),
729 + alloc_objects);
730 memcpy(&deduplicated_entries[*nr_objects],
731 &fanout.entries[cur_object],
732 sizeof(struct pack_midx_entry));