Skip to content

Commit d349f6e

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 4c2d8bd commit d349f6e

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

18781878
static void write_object_file_prepare(const struct git_hash_algo *algo,
1879-
const void *buf, unsigned long len,
1879+
const void *buf, size_t len,
18801880
enum object_type type, struct object_id *oid,
1881-
char *hdr, int *hdrlen)
1881+
char *hdr, size_t *hdrlen)
18821882
{
18831883
git_hash_ctx c;
18841884

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

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

19461946
static void hash_object_file_literally(const struct git_hash_algo *algo,
1947-
const void *buf, unsigned long len,
1947+
const void *buf, size_t len,
19481948
const char *type, struct object_id *oid)
19491949
{
19501950
char hdr[MAX_HEADER_LEN];
1951-
int hdrlen = sizeof(hdr);
1951+
size_t hdrlen = sizeof(hdr);
19521952

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

19561956
void hash_object_file(const struct git_hash_algo *algo, const void *buf,
1957-
unsigned long len, enum object_type type,
1957+
size_t len, enum object_type type,
19581958
struct object_id *oid)
19591959
{
19601960
hash_object_file_literally(algo, buf, len, type_name(type), oid);
@@ -2318,7 +2318,7 @@ int stream_loose_object(struct input_stream *in_stream, size_t len,
23182318
return err;
23192319
}
23202320

2321-
int write_object_file_flags(const void *buf, unsigned long len,
2321+
int write_object_file_flags(const void *buf, size_t len,
23222322
enum object_type type, struct object_id *oid,
23232323
struct object_id *compat_oid_in, unsigned flags)
23242324
{
@@ -2327,7 +2327,7 @@ int write_object_file_flags(const void *buf, unsigned long len,
23272327
const struct git_hash_algo *compat = repo->compat_hash_algo;
23282328
struct object_id compat_oid;
23292329
char hdr[MAX_HEADER_LEN];
2330-
int hdrlen = sizeof(hdr);
2330+
size_t hdrlen = sizeof(hdr);
23312331

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

23732373
if (compat) {
23742374
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)