Re: Syntax for partitioning - Mailing list pgsql-hackers

From Tom Lane
Subject Re: Syntax for partitioning
Date
Msg-id 15531.1258697946@sss.pgh.pa.us
Whole thread Raw
In response to Re: Syntax for partitioning  (Nikhil Sontakke <nikhil.sontakke@enterprisedb.com>)
List pgsql-hackers
Nikhil Sontakke <nikhil.sontakke@enterprisedb.com> writes:
>>> partinfo = (PartitionInfo *) malloc(ntups * sizeof(PartitionInfo));
>> 
>> 1) Please stop casting the results of palloc and malloc. �We are not
>> writing C++ here.

> I thought it was/is a good C programming practice to typecast (void *)
> always to the returning structure type!!

Yes.  The above is good style because it ensures that the variable
you're assigning the pointer to is the right type to match the sizeof
computation.  In C++ you'd use operator new instead and still have that
type-check without the cast, but indeed we are not writing C++ here.

The *real* bug in the quoted code is that it's using malloc.  There are
a few places in PG where it's appropriate to use malloc not palloc, but
pretty darn few.
        regards, tom lane


pgsql-hackers by date:

Previous
From: Stefan Kaltenbrunner
Date:
Subject: Re: Summary and Plan for Hot Standby
Next
From: Heikki Linnakangas
Date:
Subject: Re: Summary and Plan for Hot Standby