Subject: Re: Fixing a few errors and warning detected by coverity

Re: Fixing a few errors and warning detected by coverity

From: Kamil Dudka <kdudka_at_redhat.com>
Date: Fri, 3 May 2013 08:58:39 +0200

On Friday 03 May 2013 08:11:50 Jaap Keuter wrote:
> On 05/02/2013 10:51 PM, Daniel Stenberg wrote:
> > On Thu, 2 May 2013, Patrick Valsecchi wrote:
> >> A colleague ran Coverity (a static analysis tool) against c-ares and
> >> fixed a few reported errors and warnings.
> >>
> >> Please have a look at the attached patch.
> >
> > Thanks!
> >
> > There's a large amount of added typecasts for malloc() and a few other
> > void pointers in that patch. Why do we need them?
>
> Hi,
>
> It's more a matter of taste, allowing implicit casts or not. Coverity can
> be tweaked in many many ways to fit your needs.
>
> Since there are so many, it would be beneficial to have a Coverity run
> without this checker rule. Then the other changes (for 'real' problems)
> may stand out better.

The manual type-casting approach feels useless to me. It makes the code more
chatty without providing any real benefit. What would probably make sense is
a macro like this (slightly inspired by [1]):

#define NEW(T) (T *) malloc(sizeof(T))

... which ensures you allocate sufficient space to store an object of type T.

Kamil

[1] http://www.akkadia.org/drepper/defprogramming.pdf
Received on 2013-05-03