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

Re: [PATCH] sha1_name: fix segfault caused by invalid index access

From
Junio C Hamano <gitster@pobox.com>
Date
Feb 28, 2010, 18:13 UTC
Message-ID
<7vocj9cjp9.fsf@alter.siamese.dyndns.org>
In-Reply-To
<1267375122-13039-1-git-send-email-Matthieu.Moy@imag.fr>
Matthieu Moy <Matthieu.Moy@imag.fr> writes:
Show 7 quoted lines
> -	if (pos < 0)
> -		pos = -pos - 1;
> -	ce = active_cache[pos];
> -	if (ce_namelen(ce) == namelen &&
> -	    !memcmp(ce->name, filename, namelen))
> +	if (pos >= 0) {
> +		ce = active_cache[pos];

A positive return value of cache_name_pos() is "I found a merged entry with that name at this index" while a negative is "I would insert at this index if you give me a merged entry with that name".

The latter is what the name comparison logic is about. The caller asked for filename, and the return value may point at an existing entry (in which case you do not even need to memcmp(), but it doesn't hurt and simplifies the code). The nagative one with compensation could be pointing at an unrelated entry, or an unmerged entry with filename you asked, which sorts higher than a merged entry with the same name.

Previous: Matthieu MoyNext: Jeff King
Message 4 of 5 in “sha1_name: fix segfault caused by invalid index access”
  1. sha1_name: fix segfault caused by invalid index accessMarkus Heidelberg, Feb 28, 2010
  2. Matthieu MoyFeb 28, 2010
  3. sha1_name: fix segfault caused by invalid index accessMatthieu Moy, Feb 28, 2010
  4. Junio C HamanoFeb 28, 2010
  5. Jeff KingFeb 28, 2010

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.