Re: pg_malloc() versus malloc(0) - Mailing list pgsql-hackers

From Dimitri Fontaine
Subject Re: pg_malloc() versus malloc(0)
Date
Msg-id m2pq52uuxi.fsf@2ndQuadrant.fr
Whole thread Raw
In response to pg_malloc() versus malloc(0)  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: pg_malloc() versus malloc(0)  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
Tom Lane <tgl@sss.pgh.pa.us> writes:
> Namely, that on platforms where malloc(0) returns NULL instead of
> a pointer to a zero-size block, pg_malloc thinks it's a failure
> and aborts the program.

What's the use case for malloc(0) anyway?

> 1. Teach pg_malloc not to complain if result == NULL and size == 0.

What about not calling malloc at all in such places? Well I guess what
you want is for the pg_malloc() API to be able to never return NULL…

> 2. Before the malloc call, have it replace size == 0 with size = 1.

As I don't understand the need to malloc 0 byte I would think that's ok
as a way to simplify code…

Regards,
--
Dimitri Fontaine
http://2ndQuadrant.fr     PostgreSQL : Expertise, Formation et Support



pgsql-hackers by date:

Previous
From: Magnus Hagander
Date:
Subject: Re: Hash id in pg_stat_statements
Next
From: Tom Lane
Date:
Subject: Re: Extending range of to_tsvector et al