Skip to content

Commit 3d3de2f

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 379faab commit 3d3de2f

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

object-file.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ int loose_object_info(struct repository *r,
530530
static void hash_object_body(const struct git_hash_algo *algo, struct git_hash_ctx *c,
531531
const void *buf, unsigned long len,
532532
struct object_id *oid,
533-
char *hdr, int *hdrlen)
533+
char *hdr, size_t *hdrlen)
534534
{
535535
algo->init_fn(c);
536536
git_hash_update(c, hdr, *hdrlen);
@@ -539,9 +539,9 @@ static void hash_object_body(const struct git_hash_algo *algo, struct git_hash_c
539539
}
540540

541541
static void write_object_file_prepare(const struct git_hash_algo *algo,
542-
const void *buf, unsigned long len,
542+
const void *buf, size_t len,
543543
enum object_type type, struct object_id *oid,
544-
char *hdr, int *hdrlen)
544+
char *hdr, size_t *hdrlen)
545545
{
546546
struct git_hash_ctx c;
547547

@@ -682,11 +682,11 @@ int finalize_object_file_flags(const char *tmpfile, const char *filename,
682682
}
683683

684684
void hash_object_file(const struct git_hash_algo *algo, const void *buf,
685-
unsigned long len, enum object_type type,
685+
size_t len, enum object_type type,
686686
struct object_id *oid)
687687
{
688688
char hdr[MAX_HEADER_LEN];
689-
int hdrlen = sizeof(hdr);
689+
size_t hdrlen = sizeof(hdr);
690690

691691
write_object_file_prepare(algo, buf, len, type, oid, hdr, &hdrlen);
692692
}
@@ -1050,7 +1050,7 @@ int stream_loose_object(struct input_stream *in_stream, size_t len,
10501050
return err;
10511051
}
10521052

1053-
int write_object_file_flags(const void *buf, unsigned long len,
1053+
int write_object_file_flags(const void *buf, size_t len,
10541054
enum object_type type, struct object_id *oid,
10551055
struct object_id *compat_oid_in, unsigned flags)
10561056
{
@@ -1059,7 +1059,7 @@ int write_object_file_flags(const void *buf, unsigned long len,
10591059
const struct git_hash_algo *compat = repo->compat_hash_algo;
10601060
struct object_id compat_oid;
10611061
char hdr[MAX_HEADER_LEN];
1062-
int hdrlen = sizeof(hdr);
1062+
size_t hdrlen = sizeof(hdr);
10631063

10641064
/* Generate compat_oid */
10651065
if (compat) {

object-file.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ enum {
172172
WRITE_OBJECT_FILE_SILENT = (1 << 1),
173173
};
174174

175-
int write_object_file_flags(const void *buf, unsigned long len,
175+
int write_object_file_flags(const void *buf, size_t len,
176176
enum object_type type, struct object_id *oid,
177177
struct object_id *compat_oid_in, unsigned flags);
178178
static inline int write_object_file(const void *buf, unsigned long len,
@@ -223,7 +223,7 @@ int finalize_object_file_flags(const char *tmpfile, const char *filename,
223223
enum finalize_object_file_flags flags);
224224

225225
void hash_object_file(const struct git_hash_algo *algo, const void *buf,
226-
unsigned long len, enum object_type type,
226+
size_t len, enum object_type type,
227227
struct object_id *oid);
228228

229229
/* Helper to check and "touch" a file */

0 commit comments

Comments
 (0)