]> git.ipfire.org Git - thirdparty/git.git/commitdiff
use size_t to store pack .idx byte offsets
authorJeff King <peff@peff.net>
Fri, 13 Nov 2020 05:07:01 +0000 (00:07 -0500)
committerJunio C Hamano <gitster@pobox.com>
Mon, 16 Nov 2020 21:41:35 +0000 (13:41 -0800)
We sometimes store the offset into a pack .idx file as an "unsigned
long", but the mmap'd size of a pack .idx file can exceed 4GB. This is
sufficient on LP64 systems like Linux, but will be too small on LLP64
systems like Windows, where "unsigned long" is still only 32 bits. Let's
use size_t, which is a better type for an offset into a memory buffer.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/pack-redundant.c
packfile.c

index 178e3409b7f8e0477e1a41e3575bcf886c6d664b..3e70f2a4c1f0fe370bd8a1b4d1e5deba31284a48 100644 (file)
@@ -236,7 +236,7 @@ static struct pack_list * pack_list_difference(const struct pack_list *A,
 
 static void cmp_two_packs(struct pack_list *p1, struct pack_list *p2)
 {
-       unsigned long p1_off = 0, p2_off = 0, p1_step, p2_step;
+       size_t p1_off = 0, p2_off = 0, p1_step, p2_step;
        const unsigned char *p1_base, *p2_base;
        struct llist_item *p1_hint = NULL, *p2_hint = NULL;
        const unsigned int hashsz = the_hash_algo->rawsz;
@@ -280,7 +280,7 @@ static void cmp_two_packs(struct pack_list *p1, struct pack_list *p2)
 static size_t sizeof_union(struct packed_git *p1, struct packed_git *p2)
 {
        size_t ret = 0;
-       unsigned long p1_off = 0, p2_off = 0, p1_step, p2_step;
+       size_t p1_off = 0, p2_off = 0, p1_step, p2_step;
        const unsigned char *p1_base, *p2_base;
        const unsigned int hashsz = the_hash_algo->rawsz;
 
@@ -499,7 +499,7 @@ static void scan_alt_odb_packs(void)
 static struct pack_list * add_pack(struct packed_git *p)
 {
        struct pack_list l;
-       unsigned long off = 0, step;
+       size_t off = 0, step;
        const unsigned char *base;
 
        if (!p->pack_local && !(alt_odb || verbose))
index a72c2a261ffeb40015a20727da861ae94eeef7fb..63fe9ee8beeec770dc5db4837a851a68b0e69bd9 100644 (file)
@@ -164,8 +164,8 @@ int load_idx(const char *path, const unsigned int hashsz, void *idx_map,
                 * variable sized table containing 8-byte entries
                 * for offsets larger than 2^31.
                 */
-               unsigned long min_size = 8 + 4*256 + (size_t)nr*(hashsz + 4 + 4) + hashsz + hashsz;
-               unsigned long max_size = min_size;
+               size_t min_size = 8 + 4*256 + (size_t)nr*(hashsz + 4 + 4) + hashsz + hashsz;
+               size_t max_size = min_size;
                if (nr)
                        max_size += ((size_t)nr - 1)*8;
                if (idx_size < min_size || idx_size > max_size)