Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wi2Y9-000YBp-1E for pgsql-hackers@arkaria.postgresql.org; Fri, 10 Jul 2026 04:09:17 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wi2X6-00FfAk-0h for pgsql-hackers@arkaria.postgresql.org; Fri, 10 Jul 2026 04:08:12 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wi2X5-00FfAc-2q for pgsql-hackers@lists.postgresql.org; Fri, 10 Jul 2026 04:08:12 +0000 Received: from mail-yx1-xb131.google.com ([2607:f8b0:4864:20::b131]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wi2X4-00000000Pwu-1mxv for pgsql-hackers@lists.postgresql.org; Fri, 10 Jul 2026 04:08:11 +0000 Received: by mail-yx1-xb131.google.com with SMTP id 956f58d0204a3-664ce3000e6so465418d50.0 for ; Thu, 09 Jul 2026 21:08:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1783656489; cv=none; d=google.com; s=arc-20260327; b=Bt9A/f376YyS/cT1oFQXdYsV97C2yNDrZ/jzPL7q6hekSxjg40hlAtwgwIJLDf/YHb Qf1LYMpqIcdNBD0Pp0MLK+j4LpXtnuLhHum5jJnvNKvsit35DSnIueBAMhdUXaY3ErVV 1Y7BRRQ3JG2gZIJSc+Dm63oRevzDjljAoYXIkYAtLGKPmeXUeZ7V46tcndkjkdLF4btx kHlKS0dT8iJqEb5uAMkBsKnrVv2daSwHopH+sLR6mkK9Q0lvHuBNmIHDjcXoHetSfmM9 IUnSic6F/lgAL3ePzfqUfjeGf50xJVz4oUMbArzPpywRBTbF2g+Ak68aCMnymM/vkVtu wpiA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=TyxHu/h6xtI9W8EJcEZbmPtgXwVRKM1/ZADaHQJfn9M=; fh=kMfb52Zb8HjojTYVvauSveYO+RBfzxyw+rzwdKDYJXQ=; b=M8Jo8BQgH3/M/d4JXKANZSlSM/jedZPXGrjIKfLbMYuC0a7njLN04SHpEEv/Ljz8/3 Arobqt/ErySz5L9VjvpZGeJgGhB3aM95ZWBboUyv97Z2acaKQv+v4WkPLhb0zzoFFxBq knO36yfXr4F24KN+eTo87tzDRawjIcUoTByZmKwA5FC/uvMaNdtVPwQ2HvlvSZ2hHUKD Lh27I9MV3h1k3Yu+hu36+F0iUuv3O2ZbQHeAVcGe0DrsNWkA9ulzBsJRXHJUKb4RF1hM lhOiMnREvFGeJhnFWQPfQhXKF01VpE6wpJ3ymvbOY0aFx1q2eySkP+6RsE13cHUB366v UK9A==; darn=lists.postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1783656489; x=1784261289; darn=lists.postgresql.org; h=content-transfer-encoding:content-type:cc:to:subject:message-id :date:from:in-reply-to:references:mime-version:from:to:cc:subject :date:message-id:reply-to:content-type; bh=TyxHu/h6xtI9W8EJcEZbmPtgXwVRKM1/ZADaHQJfn9M=; b=prs8tiDUxNI4gF6tpfs5Uc53/7cVGtLZpHQDbys1jkNY+ew7CIpBGbqlhsHm2LZaq/ 94vNIDcvoiHHIV+iSQ2T1f+HcdBYqTpeEXWqCxP50cH0Fjd65+fqJ6kFziINIs2M0Z3t tzrYxdJbhJUlC7I4EMt34BSA1ZZITJK1/QwyV7RlMTTVFAbZWw619a83ZzgwWxRqb1x1 ms/mlejSNr7wmvidAzc9bqbRRZ2fgsz35KCZWt+A2j4MLfrdbKO9A1E85mRlLteDI+oJ FMPDUtkTSN8EL0kvvQHJEVHxj3eeDpbf7qfkVqkRdQNmiOZxbEZ6agd/1YzmWPF/zHoD LUxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783656489; x=1784261289; h=content-transfer-encoding:content-type:cc:to:subject:message-id :date:from:in-reply-to:references:mime-version:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=TyxHu/h6xtI9W8EJcEZbmPtgXwVRKM1/ZADaHQJfn9M=; b=V721aFOeIew4LBIew0vPHeq/TRaC+EUoZS979qUqObGG3kP6G1L2x0LvLc0pPMy+9d /TjaA/h2JylxIKGHJoPVQhbDAerk6nkj/T41/JyI4FdfoU93w1An5JFcpaCalqOShDC8 XWtut4SPxHERh8NV+pNiUKDY2PtNmoAkBvCdveTrU1LxpxVS76TGD+CwEtDwxTrUWhxl nuIZ2gmGs1hcezg53mgPNL5ejLgQP1+qjwmxWqgotQdcCkwWikL3KVUEzml+BH7ZYBky UVmnNGfwiMGIQI74bo81yJgyUcOZTT/vx1R+GrvPq5kLFVyZs4K8+7OJmsYgtXxb38Td mytw== X-Gm-Message-State: AOJu0YxH7L+W34LvJ9g4H9LpsZMAXLniHclzSsvA3BrzPQOqzrSqmcNC Vg7lZ2e/ybQ4SVIeQ/6K/s+q04BbEZHP4YwDukP8KkR4GzazlvP5PYbExsz6slYQLdJDzWNvdnK F8X3Q/MScLPD165vCGFFZA2ySDP8odB0y59XTLh8= X-Gm-Gg: AfdE7cn3pouV9LX5NCAljMLlRaRL3hUqm0LBsujEz/raiz7fFgaQaHX+5+sEcQNfQfz aLPZfF/L2FC5OJvaJjTN+DUFadehihDsAI8hQZ1TgMB/O4KnMvTjUKMCPHnA16SgaIu9PlrwAVc zYaNbcPSzpaID571Kli0Xnjke0nU4b2B0IUOIeIyN9ipumq7keymi31/5ScGawufDZsLHRoxxOL YWZTTZ6sJQRZ+Af/uCi2xfTDeUS+3v1u0p1IKG1mstKQMPuvrlLfZkTTnmANQ+my7zG/lTvfWTa eNwSvrRevxUKwlD2Jnwxy2AD7OefJmdy1DObi+dwMLnKLcBsx1g= X-Received: by 2002:a53:5a08:0:b0:667:8b91:2439 with SMTP id 956f58d0204a3-6679f26f7a1mr4972424d50.104.1783656488913; Thu, 09 Jul 2026 21:08:08 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Haibo Yan Date: Thu, 9 Jul 2026 21:07:58 -0700 X-Gm-Features: AVVi8CcBq3OiDqHEA6kNmsIEFaFJ8-gOnXIsrNyXXo14tWbzKF0eqyxWAjCh5Ss Message-ID: Subject: Re: [PATCH] ecpg: use memcpy in a few length-based copies To: Peter Eisentraut Cc: PostgreSQL Hackers Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Thu, Jul 9, 2026 at 12:04=E2=80=AFAM Peter Eisentraut wrote: > > 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 a= dd 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. Thank you. I should have explained that better. I am not arguing that memcpy() is generally better for string handling. Th= e sites I changed already have an explicit byte count, and some of them add t= he terminating NUL immediately afterwards. So they are not relying on strncpy= ()=E2=80=99s padding behavior. > > At a quick glance, strlcpy() might be more suitable in some of the cases > you found. > I don=E2=80=99t think strlcpy() fits these cases well. It would reserve sp= ace for a terminator, which would change exact-fit/truncation behavior in some output paths. It also treats the source as a NUL-terminated C string, while the E= CPG VARCHAR case is an arr/len buffer, not just a plain C string. I left other strncpy() calls unchanged where the source may be shorter than= the fixed-size destination, because there the stop-at-NUL and padding behavior = is still useful. Thanks, Haibo