Subject: Re: [PATCH] path-walk: fix NULL pointer dereference in error message

From: Tian Yuchen <[email-masked]>
Date: Sat, 21 Mar 2026 01:32:25 +0800

Although this isn’t covered in this patch, I’d still like to add a few 
more comments. Please allow me to elaborate a bit further:

This is the implementation of object_as_type() in object.c:

> void *object_as_type(struct object *obj, enum object_type type, int quiet)
> {
> 	if (obj->type == type)
> 		return obj;
> 	else if (obj->type == OBJ_NONE) {
> 		if (type == OBJ_COMMIT)
> 			init_commit_node((struct commit *) obj);
> 		else
> 			obj->type = type;
> 		return obj;
> 	}
> 	else {
> 		if (!quiet)
> 			error(_("object %s is a %s, not a %s"),
> 			      oid_to_hex(&obj->oid),
> 			      type_name(obj->type), type_name(type));
> 		return NULL;
> 	}
> }

There are at least two possible scenarios: the object doesn't exist, or 
the type doesn't match, right?

Then the message 'failed to find object' is misleading when user 
encounters the second scenario. Wouldn’t it be confusing if a user saw 
this message, checked the object using 'git cat-file -t', and discovered 
that the object actually exists?

Regards,

Yuchen