Re: [PATCH] path-walk: fix NULL pointer dereference in error message
- From
Tian Yuchen <a3205153416@gmail.com>
- Date
- Mar 20, 2026, 17:32 UTC
- Message-ID
- <9d0746d8-2194-4a13-812b-9b46d04c189a@gmail.com>
- In-Reply-To
- <eca1a469-2e15-4466-ae58-978ffc23c177@gmail.com>
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:
Show 19 quoted lines
> 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