Make int64_div_fast_to_numeric() more robust.
authorDean Rasheed <dean.a.rasheed@gmail.com>
Fri, 3 Feb 2023 11:13:34 +0000 (11:13 +0000)
committerDean Rasheed <dean.a.rasheed@gmail.com>
Fri, 3 Feb 2023 11:13:34 +0000 (11:13 +0000)
commitb2d47928908d7a99b8e39198d0e8e9e0cb2b024b
treed65c77ec863ca3621c9f3782d06fc19a23df07c8
parent2010d8b75a6eb0f2ce90ae24cba99775c3d343e8
Make int64_div_fast_to_numeric() more robust.

The prior coding of int64_div_fast_to_numeric() had a number of bugs
that would cause it to fail under different circumstances, such as
with log10val2 <= 0, or log10val2 a multiple of 4, or in the "slow"
numeric path with log10val2 >= 10.

None of those could be triggered by any of our current code, which
only uses log10val2 = 3 or 6. However, they made it a hazard for any
future code that might use it. Also, since this is exported by
numeric.c, users writing their own C code might choose to use it.

Therefore fix, and back-patch to v14, where it was introduced.

Dean Rasheed, reviewed by Tom Lane.

Discussion: https://postgr.es/m/CAEZATCW8gXgW0tgPxPgHDPhVX71%2BSWFRkhnXy%2BTfGDsKLepu2g%40mail.gmail.com
src/backend/utils/adt/numeric.c