Re: Avoid overflow with simplehash

From: Andres Freund <andres(at)anarazel(dot)de>
To: Ranier Vilela <ranier(dot)vf(at)gmail(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Daniel Gustafsson <daniel(at)yesql(dot)se>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Avoid overflow with simplehash
Date: 2023-07-06 17:33:24
Message-ID: 20230706173324.hn7t6khiygu6jxqe@awork3.anarazel.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

I pushed changing i to uint32 and adding Tom's comment to 11-HEAD.

On 2023-07-06 14:01:55 -0300, Ranier Vilela wrote:
> > > then will it iterate forwards?
> >
> > No, it'd still iterate backwards, but starting from the wrong place - but
> > there is no correct place to start iterating from if there is no unused
> > element.
> >
> Thanks for the confirmation.
>
> So I suppose we could have this in v1, attached.
> With comments added by Tom.

> diff --git a/src/include/lib/simplehash.h b/src/include/lib/simplehash.h
> index 48db837ec8..4fe627a921 100644
> --- a/src/include/lib/simplehash.h
> +++ b/src/include/lib/simplehash.h
> @@ -964,8 +964,8 @@ SH_DELETE_ITEM(SH_TYPE * tb, SH_ELEMENT_TYPE * entry)
> SH_SCOPE void
> SH_START_ITERATE(SH_TYPE * tb, SH_ITERATOR * iter)
> {
> - int i;
> - uint64 startelem = PG_UINT64_MAX;
> + uint32 i;
> + uint32 startelem = PG_UINT32_MAX;

The startelem type change doesn't strike me as a good idea. Currently
PG_UINT32_MAX is a valid element.

Greetings,

Andres Freund

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Gurjeet Singh 2023-07-06 17:37:21 Re: MERGE ... RETURNING
Previous Message Nathan Bossart 2023-07-06 17:20:04 Re: pgsql: Fix search_path to a safe value during maintenance operations.