Re: [PATCH 2/3] odb: widen odb_write_object() length to size_t
- From
Patrick Steinhardt <ps@pks.im>
- Date
- Nov 18, 2026, 08:25 UTC
- Message-ID
- <av1g7VQnCAcs5J1W@pks.im>
- In-Reply-To
- <20261117174353.1158905-7-christian.couder@gmail.com>
On Tue, Nov 17, 2026 at 06:43:56PM +0100, Christian Couder wrote:
Show 5 quoted lines
> odb_write_object() and odb_write_object_ext() use an `unsigned long` > for their object length argument, while almost everything they pass it > to already uses `size_t`: hash_object_file(), format_object_header(), > convert_object_file(), the `write_object` callback of `struct > odb_source`, and `git_zstream`.
Huh, I thought that we already had patches recently that converted this function to use `size_t`... oh, yes, this is overlapping with Elia's patch series [1]. I think it would make sense to rebase your patch series on top of his patches.
[1]: <20261021101640.329990-1-gitter.spiros@gmail.com>
[snip]
Show 9 quoted lines
> To fix the possible truncation issues with many callers and to prepare > for getting rid of the check, let's use `size_t` for: > > - the length argument of odb_write_object(), odb_write_object_ext(), > the odb_source_write_object() wrapper, and write_loose_object(), > > - the size stored in `struct inmemory_object`, which is later > copied back into `size_t` fields (`object_info.sizep` and > `odb_stream.size`).
Yeah, makes sense.
Show 13 quoted lines
> diff --git a/odb.c b/odb.c > index de5be285d3..56a7910b03 100644 > --- a/odb.c > +++ b/odb.c > @@ -702,7 +702,7 @@ void odb_assert_oid_type(struct object_database *odb, > } > > int odb_write_object_ext(struct object_database *odb, > - const void *buf, unsigned long len, > + const void *buf, size_t len, > enum object_type type, > struct object_id *oid, > const struct object_id *compat_oid_in,
Right. All functions that we pass `len` to already accept a `size_t`, except for `odb_source_write_object()`. But you also adapt that function at the same time, so we're good.
Show 13 quoted lines
> diff --git a/odb/source.h b/odb/source.h > index 7b56f51b82..8daf5df31c 100644 > --- a/odb/source.h > +++ b/odb/source.h > @@ -454,7 +454,7 @@ static inline int odb_source_freshen_object(struct odb_source *source, > * object ID and the compatibility object ID, if non-NULL. > */ > static inline int odb_source_write_object(struct odb_source *source, > - const void *buf, unsigned long len, > + const void *buf, size_t len, > enum object_type type, > const struct object_id *oid, > const struct object_id *compat_oid,
And the callback functions fo the backend already use a `size_t`, so those don't need to be changed.
Patrick