Skip to content

Commit f479335

Browse files
PhilipOakleydscho
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 <[email protected]> Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 06ee1ae commit f479335

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

object-file.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ int loose_object_info(struct repository *r,
503503
static void hash_object_body(const struct git_hash_algo *algo, struct git_hash_ctx *c,
504504
const void *buf, unsigned long len,
505505
struct object_id *oid,
506-
char *hdr, int *hdrlen)
506+
char *hdr, size_t *hdrlen)
507507
{
508508
algo->init_fn(c);
509509
git_hash_update(c, hdr, *hdrlen);
@@ -512,9 +512,9 @@ static void hash_object_body(const struct git_hash_algo *algo, struct git_hash_c
512512
}
513513

514514
static void write_object_file_prepare(const struct git_hash_algo *algo,
515-
const void *buf, unsigned long len,
515+
const void *buf, size_t len,
516516
enum object_type type, struct object_id *oid,
517-
char *hdr, int *hdrlen)
517+
char *hdr, size_t *hdrlen)
518518
{
519519
struct git_hash_ctx c;
520520

@@ -657,11 +657,11 @@ int finalize_object_file_flags(struct repository *repo,
657657
}
658658

659659
void hash_object_file(const struct git_hash_algo *algo, const void *buf,
660-
unsigned long len, enum object_type type,
660+
size_t len, enum object_type type,
661661
struct object_id *oid)
662662
{
663663
char hdr[MAX_HEADER_LEN];
664-
int hdrlen = sizeof(hdr);
664+
size_t hdrlen = sizeof(hdr);
665665

666666
write_object_file_prepare(algo, buf, len, type, oid, hdr, &hdrlen);
667667
}
@@ -1037,15 +1037,15 @@ int stream_loose_object(struct odb_source *source,
10371037
}
10381038

10391039
int write_object_file(struct odb_source *source,
1040-
const void *buf, unsigned long len,
1040+
const void *buf, size_t len,
10411041
enum object_type type, struct object_id *oid,
10421042
struct object_id *compat_oid_in, unsigned flags)
10431043
{
10441044
const struct git_hash_algo *algo = source->odb->repo->hash_algo;
10451045
const struct git_hash_algo *compat = source->odb->repo->compat_hash_algo;
10461046
struct object_id compat_oid;
10471047
char hdr[MAX_HEADER_LEN];
1048-
int hdrlen = sizeof(hdr);
1048+
size_t hdrlen = sizeof(hdr);
10491049

10501050
/* Generate compat_oid */
10511051
if (compat) {

object-file.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ struct object_info;
147147
int parse_loose_header(const char *hdr, struct object_info *oi);
148148

149149
int write_object_file(struct odb_source *source,
150-
const void *buf, unsigned long len,
150+
const void *buf, size_t len,
151151
enum object_type type, struct object_id *oid,
152152
struct object_id *compat_oid_in, unsigned flags);
153153

@@ -197,7 +197,7 @@ int finalize_object_file_flags(struct repository *repo,
197197
enum finalize_object_file_flags flags);
198198

199199
void hash_object_file(const struct git_hash_algo *algo, const void *buf,
200-
unsigned long len, enum object_type type,
200+
size_t len, enum object_type type,
201201
struct object_id *oid);
202202

203203
/* Helper to check and "touch" a file */

0 commit comments

Comments
 (0)