Skip to content

Commit 22c171e

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 7d65d13 commit 22c171e

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
@@ -1941,7 +1941,7 @@ void *read_object_with_reference(struct repository *r,
19411941
static void hash_object_body(const struct git_hash_algo *algo, git_hash_ctx *c,
19421942
const void *buf, unsigned long len,
19431943
struct object_id *oid,
1944-
char *hdr, int *hdrlen)
1944+
char *hdr, size_t *hdrlen)
19451945
{
19461946
algo->init_fn(c);
19471947
algo->update_fn(c, hdr, *hdrlen);
@@ -1950,9 +1950,9 @@ static void hash_object_body(const struct git_hash_algo *algo, git_hash_ctx *c,
19501950
}
19511951

19521952
static void write_object_file_prepare(const struct git_hash_algo *algo,
1953-
const void *buf, unsigned long len,
1953+
const void *buf, size_t len,
19541954
enum object_type type, struct object_id *oid,
1955-
char *hdr, int *hdrlen)
1955+
char *hdr, size_t *hdrlen)
19561956
{
19571957
git_hash_ctx c;
19581958

@@ -1966,7 +1966,7 @@ static void write_object_file_prepare(const struct git_hash_algo *algo,
19661966
static void write_object_file_prepare_literally(const struct git_hash_algo *algo,
19671967
const void *buf, size_t len,
19681968
const char *type, struct object_id *oid,
1969-
char *hdr, int *hdrlen)
1969+
char *hdr, size_t *hdrlen)
19701970
{
19711971
git_hash_ctx c;
19721972

@@ -2086,17 +2086,17 @@ int finalize_object_file_flags(const char *tmpfile, const char *filename,
20862086
}
20872087

20882088
static void hash_object_file_literally(const struct git_hash_algo *algo,
2089-
const void *buf, unsigned long len,
2089+
const void *buf, size_t len,
20902090
const char *type, struct object_id *oid)
20912091
{
20922092
char hdr[MAX_HEADER_LEN];
2093-
int hdrlen = sizeof(hdr);
2093+
size_t hdrlen = sizeof(hdr);
20942094

20952095
write_object_file_prepare_literally(algo, buf, len, type, oid, hdr, &hdrlen);
20962096
}
20972097

20982098
void hash_object_file(const struct git_hash_algo *algo, const void *buf,
2099-
unsigned long len, enum object_type type,
2099+
size_t len, enum object_type type,
21002100
struct object_id *oid)
21012101
{
21022102
hash_object_file_literally(algo, buf, len, type_name(type), oid);
@@ -2462,7 +2462,7 @@ int stream_loose_object(struct input_stream *in_stream, size_t len,
24622462
return err;
24632463
}
24642464

2465-
int write_object_file_flags(const void *buf, unsigned long len,
2465+
int write_object_file_flags(const void *buf, size_t len,
24662466
enum object_type type, struct object_id *oid,
24672467
struct object_id *compat_oid_in, unsigned flags)
24682468
{
@@ -2471,7 +2471,7 @@ int write_object_file_flags(const void *buf, unsigned long len,
24712471
const struct git_hash_algo *compat = repo->compat_hash_algo;
24722472
struct object_id compat_oid;
24732473
char hdr[MAX_HEADER_LEN];
2474-
int hdrlen = sizeof(hdr);
2474+
size_t hdrlen = sizeof(hdr);
24752475

24762476
/* Generate compat_oid */
24772477
if (compat) {
@@ -2511,8 +2511,8 @@ int write_object_file_literally(const void *buf, size_t len,
25112511
const struct git_hash_algo *algo = repo->hash_algo;
25122512
const struct git_hash_algo *compat = repo->compat_hash_algo;
25132513
struct object_id compat_oid;
2514-
int hdrlen, status = 0;
2515-
int compat_type = -1;
2514+
size_t hdrlen;
2515+
int status = 0, compat_type = -1;
25162516

25172517
if (compat) {
25182518
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
@@ -265,10 +265,10 @@ void *repo_read_object_file(struct repository *r,
265265
int oid_object_info(struct repository *r, const struct object_id *, unsigned long *);
266266

267267
void hash_object_file(const struct git_hash_algo *algo, const void *buf,
268-
unsigned long len, enum object_type type,
268+
size_t len, enum object_type type,
269269
struct object_id *oid);
270270

271-
int write_object_file_flags(const void *buf, unsigned long len,
271+
int write_object_file_flags(const void *buf, size_t len,
272272
enum object_type type, struct object_id *oid,
273273
struct object_id *comapt_oid_in, unsigned flags);
274274
static inline int write_object_file(const void *buf, unsigned long len,

0 commit comments

Comments
 (0)