Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 17 Jan 2013 13:07:31 +1100 (EST)
From:      Bruce Evans <brde@optusnet.com.au>
To:        Eitan Adler <eadler@freebsd.org>
Cc:        "svn-src-head@freebsd.org" <svn-src-head@freebsd.org>, Xin LI <delphij@gmail.com>, "svn-src-all@freebsd.org" <svn-src-all@freebsd.org>, "src-committers@freebsd.org" <src-committers@freebsd.org>, d@delphij.net
Subject:   Re: svn commit: r245494 - head/bin/pwait
Message-ID:  <20130117125124.T1066@besplex.bde.org>
In-Reply-To: <CAF6rxgn0sxXbRko0R5nKG%2BySQXqWxxurCGPhzr5t6mpGXHAT2A@mail.gmail.com>
References:  <201301160503.r0G53qie087155@svn.freebsd.org> <CAGMYy3smQv4-3oxZBFC1EkJQr%2B=3n08z=tBr_Lt58zxfTcYB6Q@mail.gmail.com> <CAF6rxgmthYBdGeZkRaDHL0bDYCHb_pKPQiGKaWmU2id0Cd_A5g@mail.gmail.com> <50F6ED68.50602@delphij.net> <CAF6rxgn0sxXbRko0R5nKG%2BySQXqWxxurCGPhzr5t6mpGXHAT2A@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Wed, 16 Jan 2013, Eitan Adler wrote:

> On 16 January 2013 13:11, Xin Li <delphij@delphij.net> wrote:
>
>> Yes I did.  Using exit(3) tells clang that this is the final exit and
>> thus eliminates the warning.
>>
>> It sounds like a bug (or arguably a feature) that clang does not
>> recognize return in main()s...
>
> It is not a bug: see

Of course it is a bug.

> http://clang-developers.42468.n3.nabble.com/Static-analyzer-possible-memory-leak-false-positive-td4026706.html

Not much signal there.

C99 requires main() to be handled specially in hosted environments.
(In freestanding environments(), neither main() nor malloc() is special.
Now the compiler could warn about main(), but it cannot know what
malloc() does so it cannot warn about not freeing memory on return
from main().)  It requires that, if the return type of main() is
compatible with int (and thus not void), then a return from the
_initial_ call to main() is equivalent to calling exit() with an arg
equal to the return value (and that if main() doesn't explicitly return
or exit, but falls through to the closing brace, then this is equivalent
to 'return (0);'.

It seems to be permitted to call malloc() recursively (otherwise C99
w.  The warning is useful if main() is called recursively.  But few
programs call main() recursively.  pwait(1) obviously doesn't.  The
the bug is quality of implementation one.  The static analyzer is too
stupid to see that main() isn't called recursively.

Bruce



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20130117125124.T1066>