Skip to content

Commit 0e2f164

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 26250d7 commit 0e2f164

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
@@ -1899,7 +1899,7 @@ void *read_object_with_reference(struct repository *r,
18991899
static void hash_object_body(const struct git_hash_algo *algo, git_hash_ctx *c,
19001900
const void *buf, unsigned long len,
19011901
struct object_id *oid,
1902-
char *hdr, int *hdrlen)
1902+
char *hdr, size_t *hdrlen)
19031903
{
19041904
algo->init_fn(c);
19051905
algo->update_fn(c, hdr, *hdrlen);
@@ -1908,9 +1908,9 @@ static void hash_object_body(const struct git_hash_algo *algo, git_hash_ctx *c,
19081908
}
19091909

19101910
static void write_object_file_prepare(const struct git_hash_algo *algo,
1911-
const void *buf, unsigned long len,
1911+
const void *buf, size_t len,
19121912
enum object_type type, struct object_id *oid,
1913-
char *hdr, int *hdrlen)
1913+
char *hdr, size_t *hdrlen)
19141914
{
19151915
git_hash_ctx c;
19161916

@@ -1924,7 +1924,7 @@ static void write_object_file_prepare(const struct git_hash_algo *algo,
19241924
static void write_object_file_prepare_literally(const struct git_hash_algo *algo,
19251925
const void *buf, size_t len,
19261926
const char *type, struct object_id *oid,
1927-
char *hdr, int *hdrlen)
1927+
char *hdr, size_t *hdrlen)
19281928
{
19291929
git_hash_ctx c;
19301930

@@ -1976,17 +1976,17 @@ int finalize_object_file(const char *tmpfile, const char *filename)
19761976
}
19771977

19781978
static void hash_object_file_literally(const struct git_hash_algo *algo,
1979-
const void *buf, unsigned long len,
1979+
const void *buf, size_t len,
19801980
const char *type, struct object_id *oid)
19811981
{
19821982
char hdr[MAX_HEADER_LEN];
1983-
int hdrlen = sizeof(hdr);
1983+
size_t hdrlen = sizeof(hdr);
19841984

19851985
write_object_file_prepare_literally(algo, buf, len, type, oid, hdr, &hdrlen);
19861986
}
19871987

19881988
void hash_object_file(const struct git_hash_algo *algo, const void *buf,
1989-
unsigned long len, enum object_type type,
1989+
size_t len, enum object_type type,
19901990
struct object_id *oid)
19911991
{
19921992
hash_object_file_literally(algo, buf, len, type_name(type), oid);
@@ -2350,7 +2350,7 @@ int stream_loose_object(struct input_stream *in_stream, size_t len,
23502350
return err;
23512351
}
23522352

2353-
int write_object_file_flags(const void *buf, unsigned long len,
2353+
int write_object_file_flags(const void *buf, size_t len,
23542354
enum object_type type, struct object_id *oid,
23552355
struct object_id *compat_oid_in, unsigned flags)
23562356
{
@@ -2359,7 +2359,7 @@ int write_object_file_flags(const void *buf, unsigned long len,
23592359
const struct git_hash_algo *compat = repo->compat_hash_algo;
23602360
struct object_id compat_oid;
23612361
char hdr[MAX_HEADER_LEN];
2362-
int hdrlen = sizeof(hdr);
2362+
size_t hdrlen = sizeof(hdr);
23632363

23642364
/* Generate compat_oid */
23652365
if (compat) {
@@ -2399,8 +2399,8 @@ int write_object_file_literally(const void *buf, size_t len,
23992399
const struct git_hash_algo *algo = repo->hash_algo;
24002400
const struct git_hash_algo *compat = repo->compat_hash_algo;
24012401
struct object_id compat_oid;
2402-
int hdrlen, status = 0;
2403-
int compat_type = -1;
2402+
size_t hdrlen;
2403+
int status = 0, compat_type = -1;
24042404

24052405
if (compat) {
24062406
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)