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

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

From
Elia Pinto <gitter.spiros@gmail.com>
Date
Oct 30, 2026, 10:58 UTC
Message-ID
<0b1d1c5668c89e3329e246d787ec80a161bd1dac.1793357680.git.gitter.spiros@gmail.com>
In-Reply-To
<cover.1793357680.git.gitter.spiros@gmail.com>

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.

Signed-off-by: Elia Pinto <gitter.spiros@gmail.com>
---
 tree.c | 2 +-
 tree.h | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
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;
diff --git a/tree.h b/tree.h
index 677382eed8..50f0b15af4 100644
--- a/tree.h
+++ b/tree.h
@@ -10,14 +10,14 @@ struct strbuf;
 struct tree {
 	struct object object;
 	void *buffer;
-	unsigned long size;
+	size_t size;
 };
 
 extern const char *tree_type;
 
 struct tree *lookup_tree(struct repository *r, const struct object_id *oid);
 
-int parse_tree_buffer(struct tree *item, void *buffer, unsigned long size);
+int parse_tree_buffer(struct tree *item, void *buffer, size_t size);
 
 #define parse_tree_gently(t, q) repo_parse_tree_gently(the_repository, t, q)
 int repo_parse_tree_gently(struct repository *r, struct tree *item,
-- 
2.53.0
Previous: Junio C HamanoNext: Junio C Hamano
Message 4 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.