pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Return INT_MAX or INT_MIN from strtoint() on overflow.
Date: Fri, 30 Oct 2026 15:03:25 +0000
Message-ID: <E1xMo8b-00000001PqZ-3LeB@gemulon.postgresql.org> (raw)

Return INT_MAX or INT_MIN from strtoint() on overflow.

Previously, strtoint() set errno to ERANGE on overflow but returned
the result of casting the long value to int. When the value is outside
the range of int, this produces an implementation-defined result that
cannot reliably indicate the direction of overflow.  POSIX requires
strtol() to return exactly LONG_MAX or LONG_MIN on overflow, which
permits safe sign-testing or range-testing.  By analogy, make
strtoint() return INT_MAX or INT_MIN on overflow.

Back-patch, since future bug fixes may expect this behavior.

Author: Chao Li <li.evan.chao@gmail.com>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/A33EE17C-D014-4980-B3DD-AC51588A06EC@gmail.com
Backpatch-through: 14

Branch
------
REL_14_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/c2d5c09a6b5cdb056954b80e297599fffd3f6c56

Modified Files
--------------
src/common/string.c | 8 ++++++++
1 file changed, 8 insertions(+)



view thread (7+ messages)

Message-ID: <E1xMo8b-00000001PqZ-3LeB@gemulon.postgresql.org>
Permalink:  ../E1xMo8b-00000001PqZ-3LeB@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1xMo8b-00000001PqZ-3LeB@gemulon.postgresql.org

 · 

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-committers@postgresql.org
  Cc: tgl@sss.pgh.pa.us
  Subject: Re: pgsql: Return INT_MAX or INT_MIN from strtoint() on overflow.
  In-Reply-To: <E1xMo8b-00000001PqZ-3LeB@gemulon.postgresql.org>
  References: <E1xMo8b-00000001PqZ-3LeB@gemulon.postgresql.org>

* 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