avoid negating LONG_MIN in cash_out()

From: Zhihong Yu <zyu(at)yugabyte(dot)com>
To: PostgreSQL Developers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: avoid negating LONG_MIN in cash_out()
Date: 2022-08-11 17:30:07
Message-ID: CALNJ-vTVL6JKvEjHOnNxp50r8Tx6meKJ=GdP3ACwVOOkXhudLQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,
In cash_out(), we have the following code:

if (value < 0)
{
/* make the amount positive for digit-reconstruction loop */
value = -value;

The negation cannot be represented in type long when the value is LONG_MIN.
It seems we can error out when LONG_MIN is detected instead of continuing
with computation.

Please take a look at the patch and provide your feedback.

Thanks

Attachment Content-Type Size
cash-out-of-range.patch application/octet-stream 512 bytes

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2022-08-11 17:40:13 Re: avoid negating LONG_MIN in cash_out()
Previous Message Tom Lane 2022-08-11 17:19:08 Re: Cleaning up historical portability baggage