pgsql: Return INT_MAX or INT_MIN from strtoint() on overflow.
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: /messages/by-id/A33EE17C-D014-4980-B3DD-AC51588A06EC@gmail.com
Backpatch-through: 14
Branch
------
REL_17_STABLE
Details
-------
https://git.postgresql.org/pg/commitdiff/2acade963cb1c6c81c6f09a018ceca43958e1be9
Modified Files
--------------
src/common/string.c | 8 ++++++++
1 file changed, 8 insertions(+)