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

Re: [PATCH 2/2] tree: use size_t for the size of parsed trees

From
Junio C Hamano <gitster@pobox.com>
Date
Nov 18, 2026, 03:47 UTC
Message-ID
<xmqqh5he94x7.fsf@gitster.g>
In-Reply-To
<0b1d1c5668c89e3329e246d787ec80a161bd1dac.1793357680.git.gitter.spiros@gmail.com>
Elia Pinto <gitter.spiros@gmail.com> writes:
Show 10 quoted lines
> struct tree stores the size of its buffer in an "unsigned long", which
> is only 32 bits wide on Windows, and parse_tree_buffer() takes it as
> such, although repo_parse_tree_gently() gets it from odb_read_object()
> as a size_t. Callers then pass tree->size to init_tree_desc(), so with
> the previous commit a tree of 4GiB or more is still truncated on
> Windows before it gets there.
>
> Use size_t for both. parse_object_buffer() still hands an "unsigned
> long" size to parse_tree_buffer(); it is shared with the other object
> types and is left for a later change.
Sounds good to me.
Show 13 quoted lines
> diff --git a/tree.c b/tree.c
> index 53f7395e9f..d37b9bc7b1 100644
> --- a/tree.c
> +++ b/tree.c
> @@ -172,7 +172,7 @@ struct tree *lookup_tree(struct repository *r, const struct object_id *oid)
>  	return object_as_type(obj, OBJ_TREE, 0);
>  }
>  
> -int parse_tree_buffer(struct tree *item, void *buffer, unsigned long size)
> +int parse_tree_buffer(struct tree *item, void *buffer, size_t size)
>  {
>  	if (item->object.parsed)
>  		return 0;

The only caller of this function, object.c:parse_object_buffer(), has its size as ulong. Even though this alone would not help end-to-end, as a "one thing at a time" step, this patch may be OK.

Previous: Elia PintoNext: Elia Pinto
Message 5 of 6 in “tree-walk: use size_t for tree sizes”
  1. 0/2 tree-walk: use size_t for tree sizesElia Pinto, Oct 30, 2026
  2. 1/2 tree-walk: use size_t for the size of tree buffersElia Pinto, Oct 30, 2026
  3. Junio C HamanoNov 18, 2026
  4. 2/2 tree: use size_t for the size of parsed treesElia Pinto, Oct 30, 2026
  5. Junio C HamanoNov 18, 2026
  6. Elia PintoNov 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.