pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Michael Paquier <michael@paquier.xyz>
To: Ewan Young <kdbase.hack@gmail.com>
Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Cc: David Rowley <dgrowleyml@gmail.com>
Cc: Dagfinn Ilmari Mannsåker <ilmari@ilmari.org>
Cc: Daniel Gustafsson <daniel@yesql.se>
Cc: Chao Li <li.evan.chao@gmail.com>
Subject: Re: Use pg_neg_s*_overflow() for open-coded negation overflow checks
Date: Mon, 31 Aug 2026 16:26:06 +0900
Message-ID: <apUsjiBcAc0wBIdo@paquier.xyz> (raw)
In-Reply-To: <CAON2xHO4tTFiow2KKLbpiOEJNL4Th5p1QVTm4mSdEU+KW1rrfQ@mail.gmail.com>
References: <CAON2xHO4tTFiow2KKLbpiOEJNL4Th5p1QVTm4mSdEU+KW1rrfQ@mail.gmail.com>

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 == 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, 

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 = arg1;

-   /* If the result is INT64_MIN, it cannot be represented. */

Comment removed.  Perhaps it should not.

-       if (unlikely(c == 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

Attachments:

  signature.asc (application/pgp-signature, 832B) download

view thread (7+ messages)  latest in thread

Message-ID: <apUsjiBcAc0wBIdo@paquier.xyz>
Permalink:  ../apUsjiBcAc0wBIdo@paquier.xyz/
Also on:    postgresql.org/message-id/apUsjiBcAc0wBIdo@paquier.xyz

 · 

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-hackers@postgresql.org
  Cc: michael@paquier.xyz, kdbase.hack@gmail.com, dgrowleyml@gmail.com, ilmari@ilmari.org, daniel@yesql.se, li.evan.chao@gmail.com
  Subject: Re: Use pg_neg_s*_overflow() for open-coded negation overflow checks
  In-Reply-To: <apUsjiBcAc0wBIdo@paquier.xyz>
  References: <CAON2xHO4tTFiow2KKLbpiOEJNL4Th5p1QVTm4mSdEU+KW1rrfQ@mail.gmail.com> <apUsjiBcAc0wBIdo@paquier.xyz>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox