Skip to content

Commit 724f7e6

Browse files
PhilipOakleyGit for Windows Build Agent
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 cd8e14c commit 724f7e6

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
@@ -1787,7 +1787,7 @@ void *read_object_with_reference(struct repository *r,
17871787
static void hash_object_body(const struct git_hash_algo *algo, git_hash_ctx *c,
17881788
const void *buf, unsigned long len,
17891789
struct object_id *oid,
1790-
char *hdr, int *hdrlen)
1790+
char *hdr, size_t *hdrlen)
17911791
{
17921792
algo->init_fn(c);
17931793
algo->update_fn(c, hdr, *hdrlen);
@@ -1796,9 +1796,9 @@ static void hash_object_body(const struct git_hash_algo *algo, git_hash_ctx *c,
17961796
}
17971797

17981798
static void write_object_file_prepare(const struct git_hash_algo *algo,
1799-
const void *buf, unsigned long len,
1799+
const void *buf, size_t len,
18001800
enum object_type type, struct object_id *oid,
1801-
char *hdr, int *hdrlen)
1801+
char *hdr, size_t *hdrlen)
18021802
{
18031803
git_hash_ctx c;
18041804

@@ -1812,7 +1812,7 @@ static void write_object_file_prepare(const struct git_hash_algo *algo,
18121812
static void write_object_file_prepare_literally(const struct git_hash_algo *algo,
18131813
const void *buf, size_t len,
18141814
const char *type, struct object_id *oid,
1815-
char *hdr, int *hdrlen)
1815+
char *hdr, size_t *hdrlen)
18161816
{
18171817
git_hash_ctx c;
18181818

@@ -1871,17 +1871,17 @@ static int write_buffer(int fd, const void *buf, size_t len)
18711871
}
18721872

18731873
static void hash_object_file_literally(const struct git_hash_algo *algo,
1874-
const void *buf, unsigned long len,
1874+
const void *buf, size_t len,
18751875
const char *type, struct object_id *oid)
18761876
{
18771877
char hdr[MAX_HEADER_LEN];
1878-
int hdrlen = sizeof(hdr);
1878+
size_t hdrlen = sizeof(hdr);
18791879

18801880
write_object_file_prepare_literally(algo, buf, len, type, oid, hdr, &hdrlen);
18811881
}
18821882

18831883
void hash_object_file(const struct git_hash_algo *algo, const void *buf,
1884-
unsigned long len, enum object_type type,
1884+
size_t len, enum object_type type,
18851885
struct object_id *oid)
18861886
{
18871887
hash_object_file_literally(algo, buf, len, type_name(type), oid);
@@ -2043,12 +2043,12 @@ static int freshen_packed_object(const struct object_id *oid)
20432043
return 1;
20442044
}
20452045

2046-
int write_object_file_flags(const void *buf, unsigned long len,
2046+
int write_object_file_flags(const void *buf, size_t len,
20472047
enum object_type type, struct object_id *oid,
20482048
unsigned flags)
20492049
{
20502050
char hdr[MAX_HEADER_LEN];
2051-
int hdrlen = sizeof(hdr);
2051+
size_t hdrlen = sizeof(hdr);
20522052

20532053
/* Normally if we have it in the pack then we do not bother writing
20542054
* it out into .git/objects/??/?{38} file.
@@ -2065,7 +2065,8 @@ int write_object_file_literally(const void *buf, size_t len,
20652065
unsigned flags)
20662066
{
20672067
char *header;
2068-
int hdrlen, status = 0;
2068+
size_t hdrlen;
2069+
int status = 0;
20692070

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

object-store.h

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

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

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

0 commit comments

Comments
 (0)