Subject: [PATCH 04/14] unparse_commit(): defensive programming

From: "Johannes Schindelin via GitGitGadget" <[email-masked]>
Date: Thu, 15 May 2025 12:45:29 +0000

From: Johannes Schindelin <[email-masked]>

CodeQL points out that `lookup_commit()` can return NULL values.

Signed-off-by: Johannes Schindelin <[email-masked]>
---
 commit.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/commit.c b/commit.c
index 6efdb03997d9..1cbc798e32ba 100644
--- a/commit.c
+++ b/commit.c
@@ -187,7 +187,7 @@ void unparse_commit(struct repository *r, const struct object_id *oid)
 {
 	struct commit *c = lookup_commit(r, oid);
 
-	if (!c->object.parsed)
+	if (!c || !c->object.parsed)
 		return;
 	free_commit_list(c->parents);
 	c->parents = NULL;
-- 
gitgitgadget