Skip to content

Commit 6287c85

Browse files
PhilipOakleyGit for Windows Build Agent
authored andcommitted
object-file.c: use size_t for header lengths
Continue walking the code path for the >4GB `hash-object --literally` test. The `hash_object_file_literally()` function internally uses both `hash_object_file()` and `write_object_file_prepare()`. Both function signatures use `unsigned long` rather than `size_t` for the mem buffer sizes. Use `size_t` instead, for LLP64 compatibility. While at it, convert those function's object's header buffer length to `size_t` for consistency. The value is already upcast to `uintmax_t` for print format compatibility. Note: The hash-object test still does not pass. A subsequent commit continues to walk the call tree's lower level hash functions to identify further fixes. Signed-off-by: Philip Oakley <philipoakley@iee.email> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
1 parent d1b0f2a commit 6287c85

2 files changed

Lines changed: 8 additions & 8 deletions

File tree

object-file.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ int parse_loose_header(const char *hdr, struct object_info *oi)
318318
static void hash_object_body(const struct git_hash_algo *algo, struct git_hash_ctx *c,
319319
const void *buf, unsigned long len,
320320
struct object_id *oid,
321-
char *hdr, int *hdrlen)
321+
char *hdr, size_t *hdrlen)
322322
{
323323
algo->init_fn(c);
324324
git_hash_update(c, hdr, *hdrlen);
@@ -327,9 +327,9 @@ static void hash_object_body(const struct git_hash_algo *algo, struct git_hash_c
327327
}
328328

329329
void write_object_file_prepare(const struct git_hash_algo *algo,
330-
const void *buf, unsigned long len,
330+
const void *buf, size_t len,
331331
enum object_type type, struct object_id *oid,
332-
char *hdr, int *hdrlen)
332+
char *hdr, size_t *hdrlen)
333333
{
334334
struct git_hash_ctx c;
335335

@@ -472,11 +472,11 @@ int finalize_object_file_flags(struct repository *repo,
472472
}
473473

474474
void hash_object_file(const struct git_hash_algo *algo, const void *buf,
475-
unsigned long len, enum object_type type,
475+
size_t len, enum object_type type,
476476
struct object_id *oid)
477477
{
478478
char hdr[MAX_HEADER_LEN];
479-
int hdrlen = sizeof(hdr);
479+
size_t hdrlen = sizeof(hdr);
480480

481481
write_object_file_prepare(algo, buf, len, type, oid, hdr, &hdrlen);
482482
}

object-file.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,12 +131,12 @@ int finalize_object_file_flags(struct repository *repo,
131131
enum finalize_object_file_flags flags);
132132

133133
void hash_object_file(const struct git_hash_algo *algo, const void *buf,
134-
unsigned long len, enum object_type type,
134+
size_t len, enum object_type type,
135135
struct object_id *oid);
136136
void write_object_file_prepare(const struct git_hash_algo *algo,
137-
const void *buf, unsigned long len,
137+
const void *buf, size_t len,
138138
enum object_type type, struct object_id *oid,
139-
char *hdr, int *hdrlen);
139+
char *hdr, size_t *hdrlen);
140140
int write_loose_object(struct odb_source_loose *loose,
141141
const struct object_id *oid, char *hdr,
142142
int hdrlen, const void *buf, unsigned long len,

0 commit comments

Comments
 (0)