Re: pgsql: Add missing string terminator

Поиск
Список
Период
Сортировка
От David Rowley
Тема Re: pgsql: Add missing string terminator
Дата
Msg-id CAApHDvpjjHS=1zjuh3F=uE10gwn_mapPv5JPgQu1Z4-8H949=w@mail.gmail.com
обсуждение исходный текст
Ответ на Re: pgsql: Add missing string terminator  (Peter Eisentraut <peter@eisentraut.org>)
Ответы Re: pgsql: Add missing string terminator
Список 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 по дате отправления: