Re: pnstrdup considered armed and dangerous

From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Andres Freund <andres(at)anarazel(dot)de>
Cc: "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: pnstrdup considered armed and dangerous
Date: 2016-10-04 13:01:30
Message-ID: CA+TgmoaEa03oNe-vx1ZaeW_-dXpX1pyct=U_8vM7dNTYsxsh_Q@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Mon, Oct 3, 2016 at 5:55 PM, Andres Freund <andres(at)anarazel(dot)de> wrote:
> /*
> * pnstrdup
> * Like pstrdup(), but append null byte to a
> * not-necessarily-null-terminated input string.
> */
> char *
> pnstrdup(const char *in, Size len)
> {
> char *out = palloc(len + 1);
>
> memcpy(out, in, len);
> out[len] = '\0';
> return out;
> }
>
> isn't that a somewhat weird behaviour / implementation? Not really like
> strndup(), which one might believe to be analoguous...

Yikes!

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message David Steele 2016-10-04 13:07:06 Re: Renaming of pg_xlog and pg_clog
Previous Message Chenxi Li 2016-10-04 12:05:06 Cardinality estimation for group by