pgsql: Return INT_MAX or INT_MIN from strtoint() on overflow.

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Return INT_MAX or INT_MIN from strtoint() on overflow.
Date: 2026-10-30 15:03:25
Message-ID: E1xMo8b-00000001PqX-3GRg@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

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(dot)evan(dot)chao(at)gmail(dot)com>
Reviewed-by: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Discussion: https://postgr.es/m/A33EE17C-D014-4980-B3DD-AC51588A06EC@gmail.com
Backpatch-through: 14

Branch
------
REL_15_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/756cbe36c63d24a9404f7698829c75f34f741e46

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

Browse pgsql-committers by date

  From Date Subject
Next Message Robert Haas 2026-10-30 16:45:31 pgsql: pg_stash_advice: Fix race conditions in 001_persist.pl
Previous Message Fujii Masao 2026-10-30 11:53:30 pgsql: Fix crash-restart race in 041_checkpoint_at_promote.pl