Skip to content

Commit 7c769f5

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 abce27e commit 7c769f5

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

object-file.c

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1780,7 +1780,7 @@ void *read_object_with_reference(struct repository *r,
17801780
static void hash_object_body(const struct git_hash_algo *algo, git_hash_ctx *c,
17811781
const void *buf, unsigned long len,
17821782
struct object_id *oid,
1783-
char *hdr, int *hdrlen)
1783+
char *hdr, size_t *hdrlen)
17841784
{
17851785
algo->init_fn(c);
17861786
algo->update_fn(c, hdr, *hdrlen);
@@ -1789,9 +1789,9 @@ static void hash_object_body(const struct git_hash_algo *algo, git_hash_ctx *c,
17891789
}
17901790

17911791
static void write_object_file_prepare(const struct git_hash_algo *algo,
1792-
const void *buf, unsigned long len,
1792+
const void *buf, size_t len,
17931793
enum object_type type, struct object_id *oid,
1794-
char *hdr, int *hdrlen)
1794+
char *hdr, size_t *hdrlen)
17951795
{
17961796
git_hash_ctx c;
17971797

@@ -1805,7 +1805,7 @@ static void write_object_file_prepare(const struct git_hash_algo *algo,
18051805
static void write_object_file_prepare_literally(const struct git_hash_algo *algo,
18061806
const void *buf, size_t len,
18071807
const char *type, struct object_id *oid,
1808-
char *hdr, int *hdrlen)
1808+
char *hdr, size_t *hdrlen)
18091809
{
18101810
git_hash_ctx c;
18111811

@@ -1857,17 +1857,17 @@ int finalize_object_file(const char *tmpfile, const char *filename)
18571857
}
18581858

18591859
static void hash_object_file_literally(const struct git_hash_algo *algo,
1860-
const void *buf, unsigned long len,
1860+
const void *buf, size_t len,
18611861
const char *type, struct object_id *oid)
18621862
{
18631863
char hdr[MAX_HEADER_LEN];
1864-
int hdrlen = sizeof(hdr);
1864+
size_t hdrlen = sizeof(hdr);
18651865

18661866
write_object_file_prepare_literally(algo, buf, len, type, oid, hdr, &hdrlen);
18671867
}
18681868

18691869
void hash_object_file(const struct git_hash_algo *algo, const void *buf,
1870-
unsigned long len, enum object_type type,
1870+
size_t len, enum object_type type,
18711871
struct object_id *oid)
18721872
{
18731873
hash_object_file_literally(algo, buf, len, type_name(type), oid);
@@ -2209,12 +2209,12 @@ int stream_loose_object(struct input_stream *in_stream, size_t len,
22092209
return err;
22102210
}
22112211

2212-
int write_object_file_flags(const void *buf, unsigned long len,
2212+
int write_object_file_flags(const void *buf, size_t len,
22132213
enum object_type type, struct object_id *oid,
22142214
unsigned flags)
22152215
{
22162216
char hdr[MAX_HEADER_LEN];
2217-
int hdrlen = sizeof(hdr);
2217+
size_t hdrlen = sizeof(hdr);
22182218

22192219
/* Normally if we have it in the pack then we do not bother writing
22202220
* it out into .git/objects/??/?{38} file.
@@ -2231,7 +2231,8 @@ int write_object_file_literally(const void *buf, size_t len,
22312231
unsigned flags)
22322232
{
22332233
char *header;
2234-
int hdrlen, status = 0;
2234+
size_t hdrlen;
2235+
int status = 0;
22352236

22362237
/* type string, SP, %lu of the length plus NUL must fit this */
22372238
hdrlen = strlen(type) + MAX_HEADER_LEN;

object-store-ll.h

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

249249
void hash_object_file(const struct git_hash_algo *algo, const void *buf,
250-
unsigned long len, enum object_type type,
250+
size_t len, enum object_type type,
251251
struct object_id *oid);
252252

253-
int write_object_file_flags(const void *buf, unsigned long len,
253+
int write_object_file_flags(const void *buf, size_t len,
254254
enum object_type type, struct object_id *oid,
255255
unsigned flags);
256256
static inline int write_object_file(const void *buf, unsigned long len,

0 commit comments

Comments
 (0)