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

Re: Git's static analysis

From
Robin Rosenberg <robin.rosenberg.lists@dewire.com>
Date
Feb 6, 2009, 06:11 UTC
Message-ID
<200902060711.37191.robin.rosenberg.lists@dewire.com>
In-Reply-To
<7v63jo9xbg.fsf@gitster.siamese.dyndns.org>
fredag 06 februari 2009 02:19:15 skrev Junio C Hamano:
Show 32 quoted lines
> Pieter de Bie <pdebie@ai.rug.nl> writes:
> 
> > I played around a bit with the 'Clang' static analyser, and tried to run git's
> > source code through it. It comes up with a few possible errors, so I thought
> > you might find it interesting. I took a quick glance, and it also seems to
> > have a few false positives, but it might still be worth to take a look.
> >
> > The results can be found here:
> >
> > 	http://frim.frim.nl/git-analyse/
> 
> Hmm, I took a quick look at a few, and they looked nonsense, but perhaps I
> am misreading things.
> 
> For example:
> 
>     http://frim.frim.nl/git-analyse/report-uxXiUR.html#EndPath
> 
> I am assuming that we follow the control flow of the labelled comments, so
> I followed along from [1] to [7] and then saw these:
> 
>     [8] loop condition is false, execution continues on line 1492
>     1483:   for (i = 0; i < array->nr; i++) {
>                 ...
>             }
> 
>     [9] taking false branch
>     1492:   if (array->nr <= i)
>                 return NULL;
> 
>     [10] dereference of null pointer.
>     1495:   c->object.flags |= ...
> 
> The thing is, if [8] exits, "i < array->nr" is not true anymore, and there
> is no way you can take false branch of  "if (array->nr <= i)" in the
> immediately next step [9]. and reach point [10].

The code assumes can c become null in the loop [if (!c) continue]. If that is the last iteration it comes out of the loop with c == NULL and array->nr >=i, thus not returning.

I have to dig through history until may 2008 to find this version of this code so the analysis seems a bit obsolete. The loop was rewritten in 4603ec0f960e.

-- robin
Previous: Junio C Hamano
Message 3 of 3 in “Git's static analysis”
  1. Pieter de BieFeb 5, 2009
  2. Junio C HamanoFeb 6, 2009
  3. Robin RosenbergFeb 6, 2009

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.