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 1x0wPN-004tep-2j for pgsql-hackers@arkaria.postgresql.org; Mon, 31 Aug 2026 07:26:22 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1x0wPM-00G4Qr-2j for pgsql-hackers@arkaria.postgresql.org; Mon, 31 Aug 2026 07:26:20 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1x0wPM-00G4Qi-0C for pgsql-hackers@lists.postgresql.org; Mon, 31 Aug 2026 07:26:20 +0000 Received: from fhigh-b4-smtp.messagingengine.com ([202.12.124.155]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1x0wPJ-000000029WM-1MLc for pgsql-hackers@lists.postgresql.org; Mon, 31 Aug 2026 07:26:19 +0000 Received: from phl-compute-01.internal (phl-compute-01.internal [10.202.2.41]) by mailfhigh.stl.internal (Postfix) with ESMTP id 025697A0171; Mon, 31 Aug 2026 03:26:13 -0400 (EDT) Received: from phl-frontend-04 ([10.202.2.163]) by phl-compute-01.internal (MEProxy); Mon, 31 Aug 2026 03:26:14 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paquier.xyz; h= cc:cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1788161173; x=1788247573; bh=BX2IfmBjJX KzR5IOPWIe5bDrE4Ow0pIhrcHPiyHGkes=; b=QD1ZptPJ4Z7wKU+KisZfbY1cVA t4KFdmQB7VJa9rbx+S5XeDF/lcJf0t/0Qcbk5+iI9tdAplHPaGOpwLePZoT6jCbS kSHtGXxs/8tNHp2YfR01XDK485PtyjAlhEFwmGcsMs7uaF/AfljiK8IdXDROC31Z lUFOAEDPoAF6nxto96N6ug3qCRJCmHDYZFACA9BqczYZbh5F+CjHNxAgmRCb2j55 vWAk5+0UFLBjKjA6qNrtVmWE+4xK5VjeUiMaH1HmWqns8YNRSwai0P+2Ruj+UiBP qEz+Gs8+PQx96hZnwhORiruaDFVNZwifnjnfHSn/dUiPRWQh9ksN6+JfxMYA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t= 1788161173; x=1788247573; bh=BX2IfmBjJXKzR5IOPWIe5bDrE4Ow0pIhrcH PiyHGkes=; b=aRhzuxr8c/lEn7frclqfpW0K02ewcKGcKZby6LBB0LEB2NSJtV/ Y/jv1TRvAyIqB4dyTiRv6hzoT9DKRlwj5U66+NnkNAg8H56MRd9X8+GBa7sDejpz C8QPFyV0zwSx9r9jtY+i+9XDRJIPLbJEBrAs8l/4YC2fe5AWNtdEqznTXF8KEEF2 e/zP7w3Xagkwa98gN2657hTtgDai6x0zHu1lK4z4KxgNgIZu6BFerAb+A+AAGtu9 jZb+p9uVF/CkW6ghBRyl43XEQ57PEPV4ZZHatNtsULfR1uqyiMTRuTUQ7ZQFzGTT PunJO74z6HsZEsSsbGcxaUuEMIHRQbvjLeQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: dmFkZTEdFEJYV+miAAW2891+AaShy+Sf23NJjXjkm6bCQImCI4O9n7YPkiVe4FEM4nT9R5 m/Dl0rVMvpOhsTSLU3Zbt2hl/8t1x/LXmYKvfljJfrwaF4b3ehOdg7NjI9/tZCSWsfiBk5 tyyEhf5HIJ0zwbCVR2pgTCcT9np6DSZf8aN7dSkbdZQfb4vtc6FIT9ARzCETbXbToIMDIH fzbZgjbIiICVxoSQDcRM4YWZCC9EJBs/E8EWbwrUtFtsBPkInnKSn9cI3I0bbnjostGe6f 8wtg+ddHr+nnaq29DnnKvEclTizbxMc3KdVY5z08OtG90h5MmsnulGUhyPLm9fhfJddqdu jcusaFZTdIrqtlVRo8VVVzqivGyU6YEtBurpz2D6RLdZ+Qn2hUzxIHvMPgI708/D3GXyAf PqxkOc3WcBKmtRK+vYN1Ogr/qjh7mCiOIqCrKOya1Tx7sTYXuc6TDUKAlXMy3AqD+RtJQ3 UrcdSasswtfjFgfN91OJ4BzwSF3RWQY0l/eZcxQk0vDxb72MEUbbkcH8sUWl3yQBvfNW27 Wt6UhcGDaQDrxZjXX5r6rzCtBD/wRA9paZwxy1/MrNRuwWQ6pWnjfOMlC0m6HvQg9PT3ng 1anAzF5STuDtdBTsVZq6JbjBmu1XbCZccCb0asZ7eSxtr2dWqYoadXuMH7PA X-ME-Proxy: Feedback-ID: i0fe9450f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 31 Aug 2026 03:26:11 -0400 (EDT) Date: Mon, 31 Aug 2026 16:26:06 +0900 From: Michael Paquier To: Ewan Young Cc: PostgreSQL Hackers , David Rowley , Dagfinn Ilmari =?iso-8859-1?Q?Manns=E5ker?= , Daniel Gustafsson , Chao Li Subject: Re: Use pg_neg_s*_overflow() for open-coded negation overflow checks Message-ID: References: MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="bvNdTC0JKLRZWGcl" Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --bvNdTC0JKLRZWGcl Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, Aug 27, 2026 at 01:57:59PM +0800, Ewan Young wrote: > No behavioral change: each site keeps its existing hard- or soft-error > path. - if (value =3D=3D PG_INT64_MIN) + if (pg_neg_s64_overflow(value, &result)) One could ask why you don't add an unlikely() here. But it looks to me that this locaton is right and that you could just remove the unlikely() from all the places where the overflow routines are used anyway, because they already embed some unlikely() calls for the minimum bound checks. + if (arg1 < 0 && unlikely(pg_neg_s32_overflow(arg1, &result))) ereport(ERROR,=20 Well, this should embed both conditions but we don't need an unlikely here anyway. That could also be written as the following, which seems slightly better from here in terms of the abs functions: if (arg1 < 0) { if (neg_overflow()) ereport(ERROR) } else result =3D arg1; - /* If the result is INT64_MIN, it cannot be represented. */ Comment removed. Perhaps it should not. - if (unlikely(c =3D=3D PG_INT64_MIN)) + Cash result; This pattern introduced in cash_div_int64() is inconsistent with the code in cash_mul_int64() a couple of lines above. -- Michael --bvNdTC0JKLRZWGcl Content-Type: application/pgp-signature; name=signature.asc -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAmqVLI4ACgkQnvQgOdby QH0eZg//eiStdJ1M2gtkFrp8/0Nqy+pE9HFoC4BpegJEjjDvG/JF9goMp7xFv4Ow XETCUf8tEhpDGjDD0wc0ieCic2welXpCTvkOFx4gMizAsf4zykwn9Aocjlgogkz3 Eb0TNgwcdWYgcFMAB0ZQJ+nCd4P6dDLU3ivSdisvQjKl7drZAREvzF4F/JKqedg5 ANAEz2q3Pj+fDMTq35dBERqPZ5R94Ffl+Ra6Uoof4k+KRfRbkmbxuAtPJ+uMoe9z uGh2bTE1RL9FZuxPknUwGMcioy87qZFHy93NKHvoVF5MlnrOJTEWigxiwQ+VpESl P1JJ6gFhZi6x9fVw0I458SR8hsIpSXuwpIkPcGVajBT8647JhdH2ispTrDP7Z1im OmnmlI2fCfrLV1C9I5cSRFm30EfMmX50JcDmDTWEUmhiTSjnEjfhcEERPQpaSDl6 7oCu1IS6wumsPWQijqFAQiI3pNeyzv63e3mNoqhvlZelNJp3piqolioscm3vXclw YHf7E4KJnCZ2QKhajLXTnSdY5z8qim59fm5aXSJh7r83A6vCn76bJ5W1xkAFKVYp MymZ/FetXrV2uSgPOwB79M75XG4FnhO+qGWa+Vtj2V++5ceNkM2FirTHHDQwajLZ 1ImN7qLDVXoADiwiHW8X7HRPxeOaKZROfkySFqor6ia9lKlOfhY= =Eg1g -----END PGP SIGNATURE----- --bvNdTC0JKLRZWGcl--