]> git.ipfire.org Git - thirdparty/git.git/commitdiff
object-file.c: use size_t for header lengths
authorPhilip Oakley <philipoakley@iee.email>
Tue, 16 Jun 2026 14:49:53 +0000 (14:49 +0000)
committerJunio C Hamano <gitster@pobox.com>
Tue, 16 Jun 2026 16:02:32 +0000 (09:02 -0700)
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>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
object-file.c
object-file.h
odb/source-files.c
odb/source-inmemory.c
odb/source-loose.c
odb/source.h

index 9afa842da2dc8e002011c4e99955348df7839112..dccbe0fc3ea8b908c38ddf10aeeaed670b9ce755 100644 (file)
@@ -318,7 +318,7 @@ int parse_loose_header(const char *hdr, struct object_info *oi)
 static void hash_object_body(const struct git_hash_algo *algo, struct 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);
        git_hash_update(c, hdr, *hdrlen);
@@ -327,9 +327,9 @@ static void hash_object_body(const struct git_hash_algo *algo, struct git_hash_c
 }
 
 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)
 {
        struct git_hash_ctx c;
 
@@ -472,11 +472,11 @@ out:
 }
 
 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)
 {
        char hdr[MAX_HEADER_LEN];
-       int hdrlen = sizeof(hdr);
+       size_t hdrlen = sizeof(hdr);
 
        write_object_file_prepare(algo, buf, len, type, oid, hdr, &hdrlen);
 }
index 528c4e6e697f8713b01f82c46f03c0c87eef6a6a..4c87cd160bb58a6f0ca985967dd589ad54330fe4 100644 (file)
@@ -131,12 +131,12 @@ int finalize_object_file_flags(struct repository *repo,
                               enum finalize_object_file_flags flags);
 
 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);
 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);
 int write_loose_object(struct odb_source_loose *loose,
                       const struct object_id *oid, char *hdr,
                       int hdrlen, const void *buf, unsigned long len,
index 5bdd04292253971fdfc3cb60fb9f1201a6075f2e..3b1261eba9700e7fa99c0c1e7c35ec990c63ec6b 100644 (file)
@@ -159,7 +159,7 @@ static int odb_source_files_freshen_object(struct odb_source *source,
 }
 
 static int odb_source_files_write_object(struct odb_source *source,
-                                        const void *buf, unsigned long len,
+                                        const void *buf, size_t len,
                                         enum object_type type,
                                         struct object_id *oid,
                                         struct object_id *compat_oid,
index e004566d768b01c62163c9cfef34a664ba102a56..7f1b6f46363f2e18a0b2b93f50681a83a9531049 100644 (file)
@@ -227,7 +227,7 @@ static int odb_source_inmemory_count_objects(struct odb_source *source,
 }
 
 static int odb_source_inmemory_write_object(struct odb_source *source,
-                                           const void *buf, unsigned long len,
+                                           const void *buf, size_t len,
                                            enum object_type type,
                                            struct object_id *oid,
                                            struct object_id *compat_oid UNUSED,
index 7d7ea2fb842537fe924e4761d5b56f8bbfde1e4d..4cfa5b23fc17195ef1e73e6e40d9eb96686e8bdb 100644 (file)
@@ -591,7 +591,7 @@ static int odb_source_loose_freshen_object(struct odb_source *source,
 }
 
 static int odb_source_loose_write_object(struct odb_source *source,
-                                        const void *buf, unsigned long len,
+                                        const void *buf, size_t len,
                                         enum object_type type, struct object_id *oid,
                                         struct object_id *compat_oid_in,
                                         enum odb_write_object_flags flags)
@@ -601,7 +601,7 @@ static int odb_source_loose_write_object(struct odb_source *source,
        const struct git_hash_algo *compat = source->odb->repo->compat_hash_algo;
        struct object_id compat_oid;
        char hdr[MAX_HEADER_LEN];
-       int hdrlen = sizeof(hdr);
+       size_t hdrlen = sizeof(hdr);
 
        /* Generate compat_oid */
        if (compat) {
index 2192a101b8ab0838bacada00c865bb6d04688901..1c65a05e2c4c6b9c36aba5f37865bd5b6cef3017 100644 (file)
@@ -199,7 +199,7 @@ struct odb_source {
         * return 0 on success, a negative error code otherwise.
         */
        int (*write_object)(struct odb_source *source,
-                           const void *buf, unsigned long len,
+                           const void *buf, size_t len,
                            enum object_type type,
                            struct object_id *oid,
                            struct object_id *compat_oid,