use size_t to store pack .idx byte offsets
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>
Jeff King committed
Nov 13, 2020 at 00:07 UTC
a9bc372ef8210e60d924ec6c0b46624c6d0a4033
2 files changed
+5
-5
builtin/pack-redundant.c
+3
-3
@@ -236,7 +236,7 @@ static struct pack_list * pack_list_difference(const struct pack_list *A,
236
237
static void cmp_two_packs(struct pack_list *p1, struct pack_list *p2)
238
{
239
- unsigned long p1_off = 0, p2_off = 0, p1_step, p2_step;
239
+ size_t p1_off = 0, p2_off = 0, p1_step, p2_step;
240
const unsigned char *p1_base, *p2_base;
241
struct llist_item *p1_hint = NULL, *p2_hint = NULL;
242
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)
280
static size_t sizeof_union(struct packed_git *p1, struct packed_git *p2)
281
{
282
size_t ret = 0;
283
- unsigned long p1_off = 0, p2_off = 0, p1_step, p2_step;
283
+ size_t p1_off = 0, p2_off = 0, p1_step, p2_step;
284
const unsigned char *p1_base, *p2_base;
285
const unsigned int hashsz = the_hash_algo->rawsz;
286
@@ -499,7 +499,7 @@ static void scan_alt_odb_packs(void)
499
static struct pack_list * add_pack(struct packed_git *p)
500
{
501
struct pack_list l;
502
- unsigned long off = 0, step;
502
+ size_t off = 0, step;
503
const unsigned char *base;
504
505
if (!p->pack_local && !(alt_odb || verbose))
packfile.c
+2
-2
@@ -164,8 +164,8 @@ int load_idx(const char *path, const unsigned int hashsz, void *idx_map,
164
* variable sized table containing 8-byte entries
165
* for offsets larger than 2^31.
166
*/
167
- unsigned long min_size = 8 + 4*256 + (size_t)nr*(hashsz + 4 + 4) + hashsz + hashsz;
168
- unsigned long max_size = min_size;
167
+ size_t min_size = 8 + 4*256 + (size_t)nr*(hashsz + 4 + 4) + hashsz + hashsz;
168
+ size_t max_size = min_size;
169
if (nr)
170
max_size += ((size_t)nr - 1)*8;
171
if (idx_size < min_size || idx_size > max_size)