Re: Review: plpgsql.extra_warnings, plpgsql.extra_errors - Mailing list pgsql-hackers

From Piotr Stefaniak
Subject Re: Review: plpgsql.extra_warnings, plpgsql.extra_errors
Date
Msg-id BLU0-SMTP1051D8288051C0ED70B6390F2780@phx.gbl
Whole thread Raw
In response to Re: Review: plpgsql.extra_warnings, plpgsql.extra_errors  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: Review: plpgsql.extra_warnings, plpgsql.extra_errors  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
On 03/22/2014 04:00 PM, Tom Lane wrote:
> That argument is entirely bogus, as it considers only one possible way
> in which the call could be wrong; a way that is of very low probability
> in PG usage, since we include <stdlib.h> in our core headers.  Besides
> which, as noted in the page itself, most modern compilers would warn
> anyway if you forgot the inclusion.
>
Apart from what the page says, I also think of casting malloc() as bad 
style and felt the need to bring this up. But since you pointed out why 
you don't want to remove the cast, I withdraw my previous suggestion.

> On the other side, coding with the explicit cast helps guard against far
> more dangerous coding errors, which the compiler will *not* help you with.
> What if myextra is actually of type "int64 *"?  In that case you probably
> meant to make enough space for an int64 not an int.  But without the cast,
> you won't be told you did anything wrong.  This is a particular hazard if
> you change your mind later on about the type of myextra.  (A colleague
> at Salesforce got burnt in exactly that way, just a couple days ago.)
>
So perhaps this alternative:  myextra = malloc(sizeof *myextra);


PS.
Coding style matters to me, but I was and still am far from insisting on 
anything.



pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: Inheritance of foregn key constraints.
Next
From: Tom Lane
Date:
Subject: Re: Review: plpgsql.extra_warnings, plpgsql.extra_errors