This is an automated email from the ASF dual-hosted git repository.

leborchuk pushed a commit to branch REL_2_STABLE
in repository https://gitbox.apache.org/repos/asf/cloudberry.git

commit dc6e2022cb43ac387e3b314b7b558db566545ad1
Author: Dean Rasheed <[email protected]>
AuthorDate: Thu Nov 9 09:55:39 2023 +0000

    Fix corner-case 64-bit integer subtraction bug on some platforms.
    
    When computing "0 - INT64_MIN", most platforms would report an
    overflow error, which is correct. However, platforms without integer
    overflow builtins or 128-bit integers would fail to spot the overflow,
    and incorrectly return INT64_MIN.
    
    Back-patch to all supported branches.
    
    Patch be me. Thanks to Jian He for initial investigation, and Laurenz
    Albe and Tom Lane for review.
    
    Discussion: 
https://postgr.es/m/CAEZATCUNK-AZSD0jVdgkk0N%3DNcAXBWeAEX-QU9AnJPensikmdQ%40mail.gmail.com
    (cherry picked from commit dea12b40d5210332453f4350e1653048b43fdb7a)
---
 src/test/regress/expected/int8.out | 2 ++
 src/test/regress/sql/int8.sql      | 1 +
 2 files changed, 3 insertions(+)

diff --git a/src/test/regress/expected/int8.out 
b/src/test/regress/expected/int8.out
index 92ccb25e93c..3651b405256 100644
--- a/src/test/regress/expected/int8.out
+++ b/src/test/regress/expected/int8.out
@@ -663,6 +663,8 @@ select -('-9223372036854775807'::int8);
 
 select -('-9223372036854775808'::int8);
 ERROR:  bigint out of range
+select 0::int8 - '-9223372036854775808'::int8;
+ERROR:  bigint out of range
 select '9223372036854775800'::int8 + '9223372036854775800'::int8;
 ERROR:  bigint out of range
 select '-9223372036854775800'::int8 + '-9223372036854775800'::int8;
diff --git a/src/test/regress/sql/int8.sql b/src/test/regress/sql/int8.sql
index 15e4ead7dc8..bae13ab145d 100644
--- a/src/test/regress/sql/int8.sql
+++ b/src/test/regress/sql/int8.sql
@@ -136,6 +136,7 @@ select '9223372036854775808'::int8;
 
 select -('-9223372036854775807'::int8);
 select -('-9223372036854775808'::int8);
+select 0::int8 - '-9223372036854775808'::int8;
 
 select '9223372036854775800'::int8 + '9223372036854775800'::int8;
 select '-9223372036854775800'::int8 + '-9223372036854775800'::int8;


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to