Skip to content

Commit f31959d

Browse files
PhilipOakleymjcheetham
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 60c04af commit f31959d

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
@@ -1781,7 +1781,7 @@ void *read_object_with_reference(struct repository *r,
17811781
static void hash_object_body(const struct git_hash_algo *algo, git_hash_ctx *c,
17821782
const void *buf, unsigned long len,
17831783
struct object_id *oid,
1784-
char *hdr, int *hdrlen)
1784+
char *hdr, size_t *hdrlen)
17851785
{
17861786
algo->init_fn(c);
17871787
algo->update_fn(c, hdr, *hdrlen);
@@ -1790,9 +1790,9 @@ static void hash_object_body(const struct git_hash_algo *algo, git_hash_ctx *c,
17901790
}
17911791

17921792
static void write_object_file_prepare(const struct git_hash_algo *algo,
1793-
const void *buf, unsigned long len,
1793+
const void *buf, size_t len,
17941794
enum object_type type, struct object_id *oid,
1795-
char *hdr, int *hdrlen)
1795+
char *hdr, size_t *hdrlen)
17961796
{
17971797
git_hash_ctx c;
17981798

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

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

18601860
static void hash_object_file_literally(const struct git_hash_algo *algo,
1861-
const void *buf, unsigned long len,
1861+
const void *buf, size_t len,
18621862
const char *type, struct object_id *oid)
18631863
{
18641864
char hdr[MAX_HEADER_LEN];
1865-
int hdrlen = sizeof(hdr);
1865+
size_t hdrlen = sizeof(hdr);
18661866

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

18701870
void hash_object_file(const struct git_hash_algo *algo, const void *buf,
1871-
unsigned long len, enum object_type type,
1871+
size_t len, enum object_type type,
18721872
struct object_id *oid)
18731873
{
18741874
hash_object_file_literally(algo, buf, len, type_name(type), oid);
@@ -2210,12 +2210,12 @@ int stream_loose_object(struct input_stream *in_stream, size_t len,
22102210
return err;
22112211
}
22122212

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

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

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

object-store.h

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

253253
void hash_object_file(const struct git_hash_algo *algo, const void *buf,
254-
unsigned long len, enum object_type type,
254+
size_t len, enum object_type type,
255255
struct object_id *oid);
256256

257-
int write_object_file_flags(const void *buf, unsigned long len,
257+
int write_object_file_flags(const void *buf, size_t len,
258258
enum object_type type, struct object_id *oid,
259259
unsigned flags);
260260
static inline int write_object_file(const void *buf, unsigned long len,

0 commit comments

Comments
 (0)