Skip to content

Commit afc175f

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 375bfa7 commit afc175f

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

object-file.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1937,7 +1937,7 @@ void *read_object_with_reference(struct repository *r,
19371937
static void hash_object_body(const struct git_hash_algo *algo, git_hash_ctx *c,
19381938
const void *buf, unsigned long len,
19391939
struct object_id *oid,
1940-
char *hdr, int *hdrlen)
1940+
char *hdr, size_t *hdrlen)
19411941
{
19421942
algo->init_fn(c);
19431943
algo->update_fn(c, hdr, *hdrlen);
@@ -1946,9 +1946,9 @@ static void hash_object_body(const struct git_hash_algo *algo, git_hash_ctx *c,
19461946
}
19471947

19481948
static void write_object_file_prepare(const struct git_hash_algo *algo,
1949-
const void *buf, unsigned long len,
1949+
const void *buf, size_t len,
19501950
enum object_type type, struct object_id *oid,
1951-
char *hdr, int *hdrlen)
1951+
char *hdr, size_t *hdrlen)
19521952
{
19531953
git_hash_ctx c;
19541954

@@ -1962,7 +1962,7 @@ static void write_object_file_prepare(const struct git_hash_algo *algo,
19621962
static void write_object_file_prepare_literally(const struct git_hash_algo *algo,
19631963
const void *buf, size_t len,
19641964
const char *type, struct object_id *oid,
1965-
char *hdr, int *hdrlen)
1965+
char *hdr, size_t *hdrlen)
19661966
{
19671967
git_hash_ctx c;
19681968

@@ -2100,17 +2100,17 @@ int finalize_object_file_flags(const char *tmpfile, const char *filename,
21002100
}
21012101

21022102
static void hash_object_file_literally(const struct git_hash_algo *algo,
2103-
const void *buf, unsigned long len,
2103+
const void *buf, size_t len,
21042104
const char *type, struct object_id *oid)
21052105
{
21062106
char hdr[MAX_HEADER_LEN];
2107-
int hdrlen = sizeof(hdr);
2107+
size_t hdrlen = sizeof(hdr);
21082108

21092109
write_object_file_prepare_literally(algo, buf, len, type, oid, hdr, &hdrlen);
21102110
}
21112111

21122112
void hash_object_file(const struct git_hash_algo *algo, const void *buf,
2113-
unsigned long len, enum object_type type,
2113+
size_t len, enum object_type type,
21142114
struct object_id *oid)
21152115
{
21162116
hash_object_file_literally(algo, buf, len, type_name(type), oid);
@@ -2476,7 +2476,7 @@ int stream_loose_object(struct input_stream *in_stream, size_t len,
24762476
return err;
24772477
}
24782478

2479-
int write_object_file_flags(const void *buf, unsigned long len,
2479+
int write_object_file_flags(const void *buf, size_t len,
24802480
enum object_type type, struct object_id *oid,
24812481
struct object_id *compat_oid_in, unsigned flags)
24822482
{
@@ -2485,7 +2485,7 @@ int write_object_file_flags(const void *buf, unsigned long len,
24852485
const struct git_hash_algo *compat = repo->compat_hash_algo;
24862486
struct object_id compat_oid;
24872487
char hdr[MAX_HEADER_LEN];
2488-
int hdrlen = sizeof(hdr);
2488+
size_t hdrlen = sizeof(hdr);
24892489

24902490
/* Generate compat_oid */
24912491
if (compat) {
@@ -2525,8 +2525,8 @@ int write_object_file_literally(const void *buf, size_t len,
25252525
const struct git_hash_algo *algo = repo->hash_algo;
25262526
const struct git_hash_algo *compat = repo->compat_hash_algo;
25272527
struct object_id compat_oid;
2528-
int hdrlen, status = 0;
2529-
int compat_type = -1;
2528+
size_t hdrlen;
2529+
int status = 0, compat_type = -1;
25302530

25312531
if (compat) {
25322532
compat_type = type_from_string_gently(type, -1, 1);

object-store-ll.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,10 +270,10 @@ void *repo_read_object_file(struct repository *r,
270270
int oid_object_info(struct repository *r, const struct object_id *, unsigned long *);
271271

272272
void hash_object_file(const struct git_hash_algo *algo, const void *buf,
273-
unsigned long len, enum object_type type,
273+
size_t len, enum object_type type,
274274
struct object_id *oid);
275275

276-
int write_object_file_flags(const void *buf, unsigned long len,
276+
int write_object_file_flags(const void *buf, size_t len,
277277
enum object_type type, struct object_id *oid,
278278
struct object_id *comapt_oid_in, unsigned flags);
279279
static inline int write_object_file(const void *buf, unsigned long len,

0 commit comments

Comments
 (0)