Skip to content

Commit

Permalink
object-file.c: use size_t for header lengths
Browse files Browse the repository at this point in the history
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 <philipoakley@iee.email>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
  • Loading branch information
PhilipOakley authored and dscho committed Sep 22, 2022
1 parent 1ee67eb commit 34b4f68
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
21 changes: 11 additions & 10 deletions object-file.c
Expand Up @@ -1787,7 +1787,7 @@ void *read_object_with_reference(struct repository *r,
static void hash_object_body(const struct git_hash_algo *algo, git_hash_ctx *c,
const void *buf, unsigned long len,
struct object_id *oid,
char *hdr, int *hdrlen)
char *hdr, size_t *hdrlen)
{
algo->init_fn(c);
algo->update_fn(c, hdr, *hdrlen);
Expand All @@ -1796,9 +1796,9 @@ static void hash_object_body(const struct git_hash_algo *algo, git_hash_ctx *c,
}

static void write_object_file_prepare(const struct git_hash_algo *algo,
const void *buf, unsigned long len,
const void *buf, size_t len,
enum object_type type, struct object_id *oid,
char *hdr, int *hdrlen)
char *hdr, size_t *hdrlen)
{
git_hash_ctx c;

Expand All @@ -1812,7 +1812,7 @@ static void write_object_file_prepare(const struct git_hash_algo *algo,
static void write_object_file_prepare_literally(const struct git_hash_algo *algo,
const void *buf, size_t len,
const char *type, struct object_id *oid,
char *hdr, int *hdrlen)
char *hdr, size_t *hdrlen)
{
git_hash_ctx c;

Expand Down Expand Up @@ -1871,17 +1871,17 @@ static int write_buffer(int fd, const void *buf, size_t len)
}

static void hash_object_file_literally(const struct git_hash_algo *algo,
const void *buf, unsigned long len,
const void *buf, size_t len,
const char *type, struct object_id *oid)
{
char hdr[MAX_HEADER_LEN];
int hdrlen = sizeof(hdr);
size_t hdrlen = sizeof(hdr);

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

void hash_object_file(const struct git_hash_algo *algo, const void *buf,
unsigned long len, enum object_type type,
size_t len, enum object_type type,
struct object_id *oid)
{
hash_object_file_literally(algo, buf, len, type_name(type), oid);
Expand Down Expand Up @@ -2223,12 +2223,12 @@ int stream_loose_object(struct input_stream *in_stream, size_t len,
return err;
}

int write_object_file_flags(const void *buf, unsigned long len,
int write_object_file_flags(const void *buf, size_t len,
enum object_type type, struct object_id *oid,
unsigned flags)
{
char hdr[MAX_HEADER_LEN];
int hdrlen = sizeof(hdr);
size_t hdrlen = sizeof(hdr);

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

/* type string, SP, %lu of the length plus NUL must fit this */
hdrlen = strlen(type) + MAX_HEADER_LEN;
Expand Down
4 changes: 2 additions & 2 deletions object-store.h
Expand Up @@ -260,10 +260,10 @@ static inline void *repo_read_object_file(struct repository *r,
int oid_object_info(struct repository *r, const struct object_id *, unsigned long *);

void hash_object_file(const struct git_hash_algo *algo, const void *buf,
unsigned long len, enum object_type type,
size_t len, enum object_type type,
struct object_id *oid);

int write_object_file_flags(const void *buf, unsigned long len,
int write_object_file_flags(const void *buf, size_t len,
enum object_type type, struct object_id *oid,
unsigned flags);
static inline int write_object_file(const void *buf, unsigned long len,
Expand Down

0 comments on commit 34b4f68

Please sign in to comment.