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

Re: [PATCH] Warn when calling deref_tag() on broken tags

From
Junio C Hamano <junkio@cox.net>
Date
Nov 2, 2005, 21:18 UTC
Message-ID
<7vbr12px3g.fsf@assigned-by-dhcp.cox.net>
In-Reply-To
<20051102204101.GE1431@pasky.or.cz>
Petr Baudis <pasky@suse.cz> writes:
Show 13 quoted lines
> +struct object *deref_tag(struct object *o, const char *refname)
>  {
> +	struct object *o2 = o;
>  	while (o && o->type == tag_type)
> -		o = parse_object(((struct tag *)o)->tagged->sha1);
> +		o = parse_object(((struct tag *)(o2 = o))->tagged->sha1);
> +	if (!o)
> +		fprintf(stderr, "warning: invalid tag %s\n",
> +		        refname ? refname
> +		        : (o2 ? sha1_to_hex(o2->sha1)
> +		           : "<unknown> (this is probably internal GIT error)"));
>  	return o;
>  }

I wonder if it would make more sense to keep the root of the traversal for this function (i.e. the original value of o) for error reporting purposes, like this:

        struct object *deref_tag(struct object *o, const char *refname)
        {
                struct object *o2 = o;
                while (o && o->type == tag_type)
                        o = parse_object(((struct tag *)o)->tagged->sha1);
                if (!o)
                        fprintf(stderr, "warning: invalid tag %s\n",
                                refname ? refname
                                : (o2 ? sha1_to_hex(o2->sha1)
                                   : "<unknown> (this is probably internal GIT error)"));
                return o;
        }
What do you think?
Other than that, the patch is OK by me.  Thanks.
Previous: Petr BaudisNext: Junio C Hamano
Message 7 of 9 in “Fix segfaults caused by invalid tags”
  1. Fix segfaults caused by invalid tagsPetr Baudis, Nov 2, 2005
  2. Johannes SchindelinNov 2, 2005
  3. Junio C HamanoNov 2, 2005
  4. Warn when calling deref_tag() on broken tagsPetr Baudis, Nov 2, 2005
  5. Johannes SchindelinNov 2, 2005
  6. Petr BaudisNov 2, 2005
  7. Junio C HamanoNov 2, 2005
  8. Junio C HamanoNov 2, 2005
  9. Petr BaudisNov 2, 2005

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.