Re: [PATCHES] backend crashing despite tsearch2 patch - Mailing list pgsql-general

From Tom Lane
Subject Re: [PATCHES] backend crashing despite tsearch2 patch
Date
Msg-id 8432.1063858900@sss.pgh.pa.us
Whole thread Raw
In response to Re: backend crashing despite tsearch2 patch  ("Nigel J. Andrews" <nandrews@investsystems.co.uk>)
List pgsql-general
"Nigel J. Andrews" <nandrews@investsystems.co.uk> writes:
> On a matter of style, it's been a while since I've seriously considered cross
> platform C. Is it the done thing to expect:
>  int *i = (int *)calloc(1,sizeof(int));
> to give the condition *i == 0 (assuming the memory allocation worked)?

calloc is defined to zero out the block of memory it returns (as opposed
to malloc which may return a block containing any random junk).

A more serious question is whether any of this code should be using
calloc/malloc as opposed to palloc.  I'd prefer to see it rewritten to
use palloc wherever possible; but that begs the question of what the
required lifespan of the allocations is.

+ #ifndef NULL
+ #define NULL ((void *)0)
+ #endif

It has been roughly twenty years since a C platform existed that didn't
predefine NULL ... and the ones that did not would likely not recognize
the ANSI-C-ism "void *".  So the above is unhelpful by any measure.

            regards, tom lane

pgsql-general by date:

Previous
From: Michael Garriss
Date:
Subject: varchar vs. text
Next
From: Ron Johnson
Date:
Subject: Re: High-volume shop uses PostgreSQL