Fix corner-case 64-bit integer subtraction bug on some platforms.

Dean Rasheed <dean.a.rasheed@gmail.com>

Commit: 4f4a0010a3a1e0404198130ac3cababeaa17d1e6
Author: Dean Rasheed <dean.a.rasheed@gmail.com>
Date: 2023-11-09T09:56:31Z
Releases: 13.14
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

Files

PathChange+/−
src/include/common/int.h modified +5 −1
src/test/regress/expected/int8.out modified +2 −0
src/test/regress/sql/int8.sql modified +1 −0

Discussion