[PATCH v3 13/13] packfile: widen `unpack_object_header_buffer()` to `size_t`
"Johannes Schindelin via GitGitGadget" <[email protected]>
| Newsgroups | org.kernel.vger.git |
|---|---|
| Message-ID | <bc4a58336a094052f636786af495adcb84ab24f8.1786632952.git.gitgitgadget@gmail.com> |
From: Johannes Schindelin <[email protected]> As part of the ongoing effort to replace `unsigned long` data types with `size_t` wherever appropriate (mainly to fix all those problems on Windows with objects larger than 4GB), let's also adjust the return type and the type of the `len` parameter of this function. Signed-off-by: Johannes Schindelin <[email protected]> --- builtin/pack-objects.c | 6 ++---- oss-fuzz/fuzz-pack-headers.c | 2 +- packfile.c | 10 ++++------ packfile.h | 3 ++- 4 files changed, 9 insertions(+), 12 deletions(-) diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c index 87aa8f44e7..d9922174f1 100644 --- a/builtin/pack-objects.c +++ b/builtin/pack-objects.c @@ -2260,8 +2260,7 @@ static void check_object(struct object_entry *entry, uint32_t object_index) int have_base = 0; struct object_id base_ref; struct object_entry *base_entry; - unsigned long used, used_0; - size_t avail; + size_t used, used_0, avail; off_t ofs; unsigned char *buf, c; enum object_type type; @@ -2773,8 +2772,7 @@ size_t oe_get_size_slow(struct packing_data *pack, struct pack_window *w_curs; unsigned char *buf; enum object_type type; - unsigned long used; - size_t avail, size; + size_t used, avail, size; if (e->type_ != OBJ_OFS_DELTA && e->type_ != OBJ_REF_DELTA) { size_t sz; diff --git a/oss-fuzz/fuzz-pack-headers.c b/oss-fuzz/fuzz-pack-headers.c index ef61ab577c..e44afe0b8d 100644 --- a/oss-fuzz/fuzz-pack-headers.c +++ b/oss-fuzz/fuzz-pack-headers.c @@ -9,7 +9,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) size_t len; unpack_object_header_buffer((const unsigned char *)data, - (unsigned long)size, &type, &len); + size, &type, &len); return 0; } diff --git a/packfile.c b/packfile.c index 629fe46a6a..faecb3cf17 100644 --- a/packfile.c +++ b/packfile.c @@ -866,12 +866,11 @@ struct packfile_list_entry *packfile_store_get_packs(struct odb_source_packed *s return store->packs.head; } -unsigned long unpack_object_header_buffer(const unsigned char *buf, - unsigned long len, enum object_type *type, size_t *sizep) +size_t unpack_object_header_buffer(const unsigned char *buf, size_t len, + enum object_type *type, size_t *sizep) { unsigned shift; - size_t size, c; - unsigned long used = 0; + size_t size, c, used = 0; c = buf[used++]; *type = (c >> 4) & 7; @@ -960,8 +959,7 @@ int unpack_object_header(struct packed_git *p, size_t *sizep) { unsigned char *base; - size_t left; - unsigned long used; + size_t left, used; enum object_type type; /* use_pack() assures us we have [base, base + 20) available diff --git a/packfile.h b/packfile.h index 3cff8bdcb9..e4e64117fb 100644 --- a/packfile.h +++ b/packfile.h @@ -300,7 +300,8 @@ int packfile_fill_entry(struct packed_git *p, int is_pack_valid(struct packed_git *); void *unpack_entry(struct repository *r, struct packed_git *, off_t, enum object_type *, size_t *); -unsigned long unpack_object_header_buffer(const unsigned char *buf, unsigned long len, enum object_type *type, size_t *sizep); +size_t unpack_object_header_buffer(const unsigned char *buf, size_t len, + enum object_type *type, size_t *sizep); size_t get_size_from_delta(struct packed_git *, struct pack_window **, off_t); int unpack_object_header(struct packed_git *, struct pack_window **, off_t *, size_t *); off_t get_delta_base(struct packed_git *p, struct pack_window **w_curs, -- gitgitgadget