pgsql: Fix incorrect return value for pg_size_pretty(bigint)

From: David Rowley <drowley(at)postgresql(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Fix incorrect return value for pg_size_pretty(bigint)
Date: 2024-07-28 10:23:48
Message-ID: E1sY148-001aTJ-63@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Fix incorrect return value for pg_size_pretty(bigint)

pg_size_pretty(bigint) would return the value in bytes rather than PB
for the smallest-most bigint value. This happened due to an incorrect
assumption that the absolute value of -9223372036854775808 could be
stored inside a signed 64-bit type.

Here we fix that by instead storing that value in an unsigned 64-bit type.

This bug does exist in versions prior to 15 but the code there is
sufficiently different and the bug seems sufficiently non-critical that
it does not seem worth risking backpatching further.

Author: Joseph Koshakow <koshy44(at)gmail(dot)com>
Discussion: https://postgr.es/m/CAAvxfHdTsMZPWEHUrZ=h3cky9Ccc3Mtx2whUHygY+ABP-mCmUw@mail.gmail.com
Backpatch-through: 15

Branch
------
REL_17_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/1e020258e53c87c697615390c42a191344bbb909

Modified Files
--------------
src/backend/utils/adt/dbsize.c | 8 ++++++--
src/test/regress/expected/dbsize.out | 8 ++++++++
src/test/regress/sql/dbsize.sql | 4 ++++
3 files changed, 18 insertions(+), 2 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message David Rowley 2024-07-28 10:24:09 pgsql: Fix incorrect return value for pg_size_pretty(bigint)
Previous Message David Rowley 2024-07-28 10:23:23 pgsql: Fix incorrect return value for pg_size_pretty(bigint)