Re: Coverity Open Source Defect Scan of PostgreSQL

From: Martijn van Oosterhout <kleptog(at)svana(dot)org>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Greg Stark <gsstark(at)mit(dot)edu>, Alvaro Herrera <alvherre(at)commandprompt(dot)com>, Neil Conway <neilc(at)samurai(dot)com>, Andreas Pflug <pgadmin(at)pse-consulting(dot)de>, ben(at)coverity(dot)com, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Coverity Open Source Defect Scan of PostgreSQL
Date: 2006-03-08 08:03:17
Message-ID: 20060308080316.GA11733@svana.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Tue, Mar 07, 2006 at 05:39:18PM -0500, Tom Lane wrote:
> Martijn van Oosterhout <kleptog(at)svana(dot)org> writes:
> > #ifdef STATIC_ANALYSIS
> > #define ereport(elevel, rest) \
> > (errstart(elevel, __FILE__, __LINE__, PG_FUNCNAME_MACRO) ? \
> > (errfinish rest) : (void) 0), (elevel >= ERROR ? exit(0) : 0)
> > #else
> > /* Normal def */
> > #endif
>
> Hmm, neat idea ... though I wonder whether either gcc or Coverity's tool
> is smart enough to draw the right conclusions from a conditional exit()
> call ...

Well, remember this is a macro so the conditional is known at compile
time and the optimiser should see that the exit is unconditional. A
quick test with the attached program shows that gcc does correctly
determine that the last few lines are unreachable and are optimised out
entirely (with -Wunreachable-code which is not the default).

I tried to create an empty static inline function with
attribute((noreturn)) to optimise out the call to exit(), but gcc
merely points out the function does actually return and proceeds to
assume that the rest of main() is also reachable.

Another possibility would be to create two versions of errfinish, one
marked (noreturn), and use a conditional on elevel to decide which to
use. However, then you get issues with multiple evaluation of macro
arguments...

gcc 3.3.5
--
Martijn van Oosterhout <kleptog(at)svana(dot)org> http://svana.org/kleptog/
> Patent. n. Genius is 5% inspiration and 95% perspiration. A patent is a
> tool for doing 5% of the work and then sitting around waiting for someone
> else to do the other 95% so you can sue them.

Attachment Content-Type Size
a.c text/x-csrc 470 bytes

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Michael Glaesemann 2006-03-08 08:11:51 Re: FW: PGBuildfarm member snake Branch HEAD Status changed from OK to PLCheck failure
Previous Message Gourish Singbal 2006-03-08 07:54:32 Re: current segfault if autovauum is on