Re: pgsql: Add missing string terminator

From: David Rowley <dgrowleyml(at)gmail(dot)com>
To: Peter Eisentraut <peter(at)eisentraut(dot)org>
Cc: Daniel Gustafsson <daniel(at)yesql(dot)se>, pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: Re: pgsql: Add missing string terminator
Date: 2025-04-30 13:14:57
Message-ID: CAApHDvpjjHS=1zjuh3F=uE10gwn_mapPv5JPgQu1Z4-8H949=w@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

On Thu, 1 May 2025 at 00:44, Peter Eisentraut <peter(at)eisentraut(dot)org> wrote:
>
> On 30.04.25 13:56, David Rowley wrote:
> > In case you're looking for inspiration on a standard to follow,
> > commits such as 586dd5d6a did seem to favour memcpy() when the length
> > was known and only use strlcpy() when it wasn't.
>
> It looks like the memcpy() uses in that commit are for cases where we
> don't want/need the null terminator.

hmm, all the execute.c ones look like they're copying the NUL char to me.

> I think it's best in general to use str* for strings and mem* for
> not-strings. That's easier to read and also better for static analyzers
> etc.

The reason I think memcpy is better is that the NUL only needs to be
found once. memcpy() is much faster than strlcpy() because it can
operate on many bytes at once rather than doing 1 byte at a time.

Performance might not matter for this case, but your reasoning isn't
specific to this case either.

David

In response to

Responses

Browse pgsql-committers by date

  From Date Subject
Next Message Tom Lane 2025-04-30 15:14:44 pgsql: Update time zone data files to tzdata release 2025b.
Previous Message Peter Eisentraut 2025-04-30 12:44:41 Re: pgsql: Add missing string terminator