git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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
Previous: Christian CouderNext: Christian Couder
Message 5 of 7 in “Allow merges with results over 2 GiB on 64-bit Windows”
  1. 0/3 Allow merges with results over 2 GiB on 64-bit WindowsChristian Couder, Nov 17, 2026
  2. 1/3 notes-merge: use size_t in write_buf_to_worktree()Christian Couder, Nov 17, 2026
  3. Patrick SteinhardtNov 18, 2026
  4. 2/3 odb: widen odb_write_object() length to size_tChristian Couder, Nov 17, 2026
  5. Patrick SteinhardtNov 18, 2026
  6. Christian CouderNov 18, 2026
  7. 3/3 xdiff: drop LONG_MAX check on merge result sizeChristian Couder, Nov 17, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.