Skip to content

Commit a9bc372

Browse files
peffgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f86f769 commit a9bc372

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

builtin/pack-redundant.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ static struct pack_list * pack_list_difference(const struct pack_list *A,
236236

237237
static void cmp_two_packs(struct pack_list *p1, struct pack_list *p2)
238238
{
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;
240240
const unsigned char *p1_base, *p2_base;
241241
struct llist_item *p1_hint = NULL, *p2_hint = NULL;
242242
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)
280280
static size_t sizeof_union(struct packed_git *p1, struct packed_git *p2)
281281
{
282282
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;
284284
const unsigned char *p1_base, *p2_base;
285285
const unsigned int hashsz = the_hash_algo->rawsz;
286286

@@ -499,7 +499,7 @@ static void scan_alt_odb_packs(void)
499499
static struct pack_list * add_pack(struct packed_git *p)
500500
{
501501
struct pack_list l;
502-
unsigned long off = 0, step;
502+
size_t off = 0, step;
503503
const unsigned char *base;
504504

505505
if (!p->pack_local && !(alt_odb || verbose))

packfile.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,8 @@ int load_idx(const char *path, const unsigned int hashsz, void *idx_map,
164164
* variable sized table containing 8-byte entries
165165
* for offsets larger than 2^31.
166166
*/
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;
169169
if (nr)
170170
max_size += ((size_t)nr - 1)*8;
171171
if (idx_size < min_size || idx_size > max_size)

0 commit comments

Comments
 (0)