Re: [PATCH] ecpg: use memcpy in a few length-based copies

From: Peter Eisentraut <peter(at)eisentraut(dot)org>
To: Haibo Yan <tristan(dot)yim(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: [PATCH] ecpg: use memcpy in a few length-based copies
Date: 2026-07-09 07:04:54
Message-ID: d3384f44-412a-47b4-b5b9-cdc64a336d2f@eisentraut.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

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.

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Bertrand Drouvot 2026-07-09 07:05:54 Re: Fix races conditions in DropRole() and GrantRole()
Previous Message Kyotaro Horiguchi 2026-07-09 06:15:40 Re: Possible replace of strncpy on xactdesc.c