Re: pgsql: Add missing string terminator - Mailing list pgsql-committers

From David Rowley
Subject Re: pgsql: Add missing string terminator
Date
Msg-id CAApHDvpjjHS=1zjuh3F=uE10gwn_mapPv5JPgQu1Z4-8H949=w@mail.gmail.com
Whole thread Raw
In response to Re: pgsql: Add missing string terminator  (Peter Eisentraut <peter@eisentraut.org>)
Responses Re: pgsql: Add missing string terminator
List pgsql-committers
On Thu, 1 May 2025 at 00:44, Peter Eisentraut <peter@eisentraut.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



pgsql-committers by date:

Previous
From: Peter Eisentraut
Date:
Subject: Re: pgsql: Add missing string terminator
Next
From: Tom Lane
Date:
Subject: pgsql: Update time zone data files to tzdata release 2025b.