pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: PG Bug reporting form <noreply@postgresql.org>
To: pgsql-bugs@lists.postgresql.org
Cc: kjs@teews.com
Subject: BUG #17128: minimum numeric 'integer' is -2147483647 not -2147483648 as documented
Date: Thu, 29 Jul 2021 22:35:01 +0000
Message-ID: <17128-55a8a879727a3e3a@postgresql.org> (raw)

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;



view thread (6+ messages)  latest in thread

Message-ID: <17128-55a8a879727a3e3a@postgresql.org>
Permalink:  ../17128-55a8a879727a3e3a@postgresql.org/
Also on:    postgresql.org/message-id/17128-55a8a879727a3e3a@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 using the --to and --cc options:
  reply via email

  To: pgsql-bugs@postgresql.org
  Cc: noreply@postgresql.org, pgsql-bugs@lists.postgresql.org, kjs@teews.com
  Subject: Re: BUG #17128: minimum numeric 'integer' is -2147483647 not -2147483648 as documented
  In-Reply-To: <17128-55a8a879727a3e3a@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