Re: Fix overflow in pg_size_pretty

From: David Rowley <dgrowleyml(at)gmail(dot)com>
To: Joseph Koshakow <koshy44(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Fix overflow in pg_size_pretty
Date: 2024-07-28 00:00:21
Message-ID: CAApHDvoRkYzK8LZaESvyuLgRjPH8ovK88YvxLTTqi5imk2+HMQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Sun, 28 Jul 2024 at 11:06, Joseph Koshakow <koshy44(at)gmail(dot)com> wrote:
> > + uint64 usize = size < 0 ? (uint64) (-size) : (uint64) size;
>
> I think that the explicit test for PG_INT64_MIN is still required. If
> `size` is equal to PG_INT64_MIN then `-size` will overflow. You end up
> with the correct behavior if `size` wraps around, but that's only
> guaranteed on platforms that support the `-fwrapv` flag.

What if we spelt it out the same way as pg_lltoa() does?

i.e: uint64 usize = size < 0 ? 0 - (uint64) size : (uint64) size;

David

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Corey Huinker 2024-07-28 01:08:44 Re: Statistics Import and Export
Previous Message Joseph Koshakow 2024-07-27 23:06:30 Re: Fix overflow in pg_size_pretty