Fix BUG #19586: money division overflow for INT64_MIN / -1

From: Andrey Rachitskiy <pl0h0yp1(at)gmail(dot)com>
To: pgsql-hackers(at)lists(dot)postgresql(dot)org
Cc: tristan(at)partin(dot)io
Subject: Fix BUG #19586: money division overflow for INT64_MIN / -1
Date: 2026-07-30 05:30:56
Message-ID: CAB8bMisnXJVXte6s3kUOpuuAY9=9kehG6MMX-+TQoFsSGan22Q@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi, Hackers!

This continues BUG #19586 (money division overflow):
https://www.postgresql.org/message-id/19586-bb603bf5ad9934dd@postgresql.org

cash_div_int64() rejects division by zero, but not INT64_MIN / -1.
On x86-64 that surfaces as a floating-point exception via SIGFPE; on
aarch64 it silently returns INT64_MIN. Multiplication by -1 is already
guarded (commit 4f96281587).
The attached patch handles division by -1 as negation, matching
int8div(), and raises "money out of range" when the dividend is
PG_INT64_MIN. Regression tests cover int8/int4/int2.

Tristan looked at the patch on -bugs and suggested posting it here.

Patch attached.

Attachment Content-Type Size
0001-Fix-money-div-INT64_MIN-by-minus-one-overflow.patch text/x-patch 3.3 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Andrey Rachitskiy 2026-07-30 05:32:00 Re: Build warning with meson and dtrace on Fedora 43
Previous Message Tender Wang 2026-07-30 05:29:25 Re: Partition pruning can incorrectly exclude a RANGE default partition