The following bug has been logged on the website:
Bug reference: 17128
Logged by: Kevin Sweet
Email address: kjs@teews.com
PostgreSQL version: 13.2
Operating system: RHEL6, RHEL7, Solaris11
Description:
I submitted a similar report to the documentation mailing list so you can
decide whether to update the documentation or the code.
The PGTYPESnumeric_to_int function deems -2147483648 to be invalid even
though it is a perfectly valid 32-bit integer because the code compares to
-INT_MAX which resolves to -2147483647 on the Fedora/Red Hat and Solaris
versions I have available to check against.
diff --git a/doc/src/sgml/ecpg.sgml b/doc/src/sgml/ecpg.sgml
index 7266e229a4..0e89f23c73 100644
--- a/doc/src/sgml/ecpg.sgml
+++ b/doc/src/sgml/ecpg.sgml
@@ -8666,7 +8666,7 @@ int dectoint(decimal *np, int *ip);
Note that the ECPG implementation differs from the
<productname>Informix</productname>
implementation. <productname>Informix</productname> limits an
integer to the range from -32767 to
32767, while the limits in the ECPG implementation depend on the
- architecture (<literal>-INT_MAX .. INT_MAX</literal>).
+ architecture (<literal>(-INT_MAX - 1) .. INT_MAX</literal>).
</para>
</listitem>
</varlistentry>
diff --git a/src/interfaces/ecpg/pgtypeslib/numeric.c
b/src/interfaces/ecpg/pgtypeslib/numeric.c
index 060fad7867..4e6c9910dc 100644
--- a/src/interfaces/ecpg/pgtypeslib/numeric.c
+++ b/src/interfaces/ecpg/pgtypeslib/numeric.c
@@ -1505,7 +1505,7 @@ PGTYPESnumeric_to_int(numeric *nv, int *ip)
if ((i = PGTYPESnumeric_to_long(nv, &l)) != 0)
return i;
- if (l < -INT_MAX || l > INT_MAX)
+ if (l < (-INT_MAX - 1) || l > INT_MAX)
{
errno = PGTYPES_NUM_OVERFLOW;
return -1;