public inbox for [email protected]
help / color / mirror / Atom feedFrom: Peter Eisentraut <[email protected]>
To: Haibo Yan <[email protected]>
To: PostgreSQL Hackers <[email protected]>
Subject: Re: [PATCH] ecpg: use memcpy in a few length-based copies
Date: Thu, 9 Jul 2026 09:04:54 +0200
Message-ID: <[email protected]> (raw)
In-Reply-To: <CABXr29HdcPfU+wC7Va9Z5WXh+Kai_63J4J-e3d-_w=EuBNFKLw@mail.gmail.com>
References: <CABXr29HdcPfU+wC7Va9Z5WXh+Kai_63J4J-e3d-_w=EuBNFKLw@mail.gmail.com>
On 08.07.26 21:24, Haibo Yan wrote:
> I noticed a few places in ecpg that use strncpy() even though the code already
> knows how many bytes to copy.
>
> For example, some paths copy N bytes into a temporary buffer and then add the
> terminating NUL explicitly. There is also one small substring copy in
> pgtypeslib/datetime.c. memcpy() seems a better fit for those cases.
Why is it better? At least strncpy() enforces that the target is a char
array, which memcpy() doesn't.
At a quick glance, strlcpy() might be more suitable in some of the cases
you found.
view thread (2+ messages)
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected], [email protected], [email protected]
Subject: Re: [PATCH] ecpg: use memcpy in a few length-based copies
In-Reply-To: <[email protected]>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox