Re: Integer undeflow in fprintf in dsa.c

From: Daniel Gustafsson <daniel(at)yesql(dot)se>
To: Ильясов Ян <ianilyasov(at)outlook(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Integer undeflow in fprintf in dsa.c
Date: 2024-02-20 12:00:19
Message-ID: DADF07F1-02BE-4B97-B8FD-EEC2AD02F999@yesql.se
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

> On 20 Feb 2024, at 12:28, Ильясов Ян <ianilyasov(at)outlook(dot)com> wrote:

> ​fprintf(stderr,
> " segment bin %zu (at least %d contiguous pages free):\n",
> i, 1 << (i - 1));
>
> In case i​ equals zero user will get "at least -2147483648 contiguous pages free".

That does indeed seem like an oversight.

> I believe that this is a mistake, and fprintf​ should print "at least 0 contiguous pages free"
> in case i​ equals zero.

The message "at least 0 contiguous pages free" reads a bit nonsensical though,
wouldn't it be preferrable to check for i being zero and print a custom message
for that case? Something like the below untested sketch?

+ if (i == 0)
+ fprintf(stderr,
+ " segment bin %zu (no contiguous free pages):\n", i);
+ else
+ fprintf(stderr,
+ " segment bin %zu (at least %d contiguous pages free):\n",
+ i, 1 << (i - 1));

--
Daniel Gustafsson

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tomas Vondra 2024-02-20 12:09:25 Re: logical decoding and replication of sequences, take 2
Previous Message Daniel Gustafsson 2024-02-20 11:51:24 Re: Replace current implementations in crypt() and gen_salt() to OpenSSL