Re: more psprintf() use

From: Andres Freund <andres(at)2ndquadrant(dot)com>
To: Heikki Linnakangas <hlinnakangas(at)vmware(dot)com>
Cc: Peter Eisentraut <peter_e(at)gmx(dot)net>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: more psprintf() use
Date: 2014-01-02 08:53:34
Message-ID: 20140102085334.GB2683@awork2.anarazel.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 2014-01-02 09:49:48 +0200, Heikki Linnakangas wrote:
> On 01/02/2014 05:14 AM, Peter Eisentraut wrote:
> >diff --git a/contrib/hstore/hstore_io.c b/contrib/hstore/hstore_io.c
> >index 772a5ca..8331a56 100644
> >--- a/contrib/hstore/hstore_io.c
> >+++ b/contrib/hstore/hstore_io.c
> >@@ -1114,11 +1114,7 @@
> > HEntry *entries = ARRPTR(in);
> >
> > if (count == 0)
> >- {
> >- out = palloc(1);
> >- *out = '\0';
> >- PG_RETURN_CSTRING(out);
> >- }
> >+ PG_RETURN_CSTRING("");
> >
> > buflen = 0;
>
> Is it legal to return a constant with PG_RETURN_CSTRING? Grepping around, I
> don't see that being done anywhere else, but there are places that do
> PG_RETURN_CSTRING(pstrdup(<constant>))...

I don't see why it wouldn't be legal - constant strings have static
storage duration, i.e. the program lifetime. And I can see nothing that
would allow pfree()ing the return value of cstring returning functions
in the general case.

Greetings,

Andres Freund

--
Andres Freund http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Andres Freund 2014-01-02 08:56:30 Re: Patch: show relation and tuple infos of a lock to acquire
Previous Message Andres Freund 2014-01-02 08:48:26 Re: preserving forensic information when we freeze