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

Re: [PATCH] list-objects: perform NULL check before the variable is dereferenced

From
Junio C Hamano <gitster@pobox.com>
Date
Apr 10, 2012, 00:09 UTC
Message-ID
<7vaa2ktplj.fsf@alter.siamese.dyndns.org>
In-Reply-To
<CACsJy8ASo8j+hmJ7Kw2uLcD9cS8SXc6yOoc5GDUcFHYk9W9a_g@mail.gmail.com>
Nguyen Thai Ngoc Duy <pclouds@gmail.com> writes:
Show 17 quoted lines
> 2012/4/10 Junio C Hamano <gitster@pobox.com>:
>> Nguyễn Thái Ngọc Duy  <pclouds@gmail.com> writes:
>>
>>> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
>>> ---
>>>  list-objects.c |   10 ++++++----
>>>  1 files changed, 6 insertions(+), 4 deletions(-)
>>
>> Please explain why this is needed?
>>
>> I can see that process_blob() is called from process_tree() which passes
>> the return value from lookup_blob(entry.sha1) directly without looking at
>> it.  lookup_blob() can issue an error message and return NULL if there is
>> a SHA-1 collision with an object that is not a blob.
>
> to avoid segmentation fault in that case, if "blob" is NULL, it dies
> at blob->object anyway and the check "if (!obj)" is useless.

Well, I didn't mean that you should explain whatever to _me_ as a response; I meant that the log message should explain that to future readers. I thought you have been here long enough to know that ;-)

Also "check NULL before dereferencing" means "avoid segmentation fault", so that is not the primary thing that needs to be explained. The point is to explain why and how a NULL could come into the codepath in the first place.

Please try again when the post-1.7.10 cycle opens.
Thanks.
Previous: Junio C Hamano
Message 5 of 5 in “list-objects: perform NULL check before the variable is dereferenced”
  1. list-objects: perform NULL check before the variable is dereferencedNguyễn Thái Ngọc Duy, Apr 9, 2012
  2. Junio C HamanoApr 9, 2012
  3. Nguyen Thai Ngoc DuyApr 9, 2012
  4. Junio C HamanoApr 10, 2012
  5. Junio C HamanoApr 10, 2012

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.