]> git.ipfire.org Git - thirdparty/git.git/commit
diff: handle NULL return from repo_get_commit_tree()
authorJohannes Schindelin <johannes.schindelin@gmx.de>
Fri, 10 Jul 2026 11:39:26 +0000 (11:39 +0000)
committerJunio C Hamano <gitster@pobox.com>
Fri, 10 Jul 2026 15:13:54 +0000 (08:13 -0700)
commitd07d09ee43b920f17d00a96ee29621e398136218
tree96fc668da09d7a1174b9567823fa6f604763dec8
parenta6b8f0143101f35bd5cc59ec5d51c9c4d428620c
diff: handle NULL return from repo_get_commit_tree()

The `repo_get_commit_tree()` function can return NULL when a commit's
tree object is not available (e.g., the commit was parsed but its
maybe_tree field is unset and the commit is not in the commit-graph). In
cmd_diff(), the return value is immediately dereferenced via ->object
without a NULL check, which would crash if the tree cannot be loaded.

Add an explicit NULL check and die with a descriptive message.

Pointed out by Coverity.

Assisted-by: Claude Opus 4.6
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/diff.c