Skip to content

Commit eb7bc6b

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 7eff60f commit eb7bc6b

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
@@ -1866,7 +1866,7 @@ void *read_object_with_reference(struct repository *r,
18661866
static void hash_object_body(const struct git_hash_algo *algo, git_hash_ctx *c,
18671867
const void *buf, unsigned long len,
18681868
struct object_id *oid,
1869-
char *hdr, int *hdrlen)
1869+
char *hdr, size_t *hdrlen)
18701870
{
18711871
algo->init_fn(c);
18721872
algo->update_fn(c, hdr, *hdrlen);
@@ -1875,9 +1875,9 @@ static void hash_object_body(const struct git_hash_algo *algo, git_hash_ctx *c,
18751875
}
18761876

18771877
static void write_object_file_prepare(const struct git_hash_algo *algo,
1878-
const void *buf, unsigned long len,
1878+
const void *buf, size_t len,
18791879
enum object_type type, struct object_id *oid,
1880-
char *hdr, int *hdrlen)
1880+
char *hdr, size_t *hdrlen)
18811881
{
18821882
git_hash_ctx c;
18831883

@@ -1891,7 +1891,7 @@ static void write_object_file_prepare(const struct git_hash_algo *algo,
18911891
static void write_object_file_prepare_literally(const struct git_hash_algo *algo,
18921892
const void *buf, size_t len,
18931893
const char *type, struct object_id *oid,
1894-
char *hdr, int *hdrlen)
1894+
char *hdr, size_t *hdrlen)
18951895
{
18961896
git_hash_ctx c;
18971897

@@ -1943,17 +1943,17 @@ int finalize_object_file(const char *tmpfile, const char *filename)
19431943
}
19441944

19451945
static void hash_object_file_literally(const struct git_hash_algo *algo,
1946-
const void *buf, unsigned long len,
1946+
const void *buf, size_t len,
19471947
const char *type, struct object_id *oid)
19481948
{
19491949
char hdr[MAX_HEADER_LEN];
1950-
int hdrlen = sizeof(hdr);
1950+
size_t hdrlen = sizeof(hdr);
19511951

19521952
write_object_file_prepare_literally(algo, buf, len, type, oid, hdr, &hdrlen);
19531953
}
19541954

19551955
void hash_object_file(const struct git_hash_algo *algo, const void *buf,
1956-
unsigned long len, enum object_type type,
1956+
size_t len, enum object_type type,
19571957
struct object_id *oid)
19581958
{
19591959
hash_object_file_literally(algo, buf, len, type_name(type), oid);
@@ -2317,7 +2317,7 @@ int stream_loose_object(struct input_stream *in_stream, size_t len,
23172317
return err;
23182318
}
23192319

2320-
int write_object_file_flags(const void *buf, unsigned long len,
2320+
int write_object_file_flags(const void *buf, size_t len,
23212321
enum object_type type, struct object_id *oid,
23222322
struct object_id *compat_oid_in, unsigned flags)
23232323
{
@@ -2326,7 +2326,7 @@ int write_object_file_flags(const void *buf, unsigned long len,
23262326
const struct git_hash_algo *compat = repo->compat_hash_algo;
23272327
struct object_id compat_oid;
23282328
char hdr[MAX_HEADER_LEN];
2329-
int hdrlen = sizeof(hdr);
2329+
size_t hdrlen = sizeof(hdr);
23302330

23312331
/* Generate compat_oid */
23322332
if (compat) {
@@ -2366,8 +2366,8 @@ int write_object_file_literally(const void *buf, size_t len,
23662366
const struct git_hash_algo *algo = repo->hash_algo;
23672367
const struct git_hash_algo *compat = repo->compat_hash_algo;
23682368
struct object_id compat_oid;
2369-
int hdrlen, status = 0;
2370-
int compat_type = -1;
2369+
size_t hdrlen;
2370+
int status = 0, compat_type = -1;
23712371

23722372
if (compat) {
23732373
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
@@ -250,10 +250,10 @@ void *repo_read_object_file(struct repository *r,
250250
int oid_object_info(struct repository *r, const struct object_id *, unsigned long *);
251251

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

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

0 commit comments

Comments
 (0)