Re: Signed vs. Unsigned (some)

From: Kyotaro Horiguchi <horikyota(dot)ntt(at)gmail(dot)com>
To: ranier(dot)vf(at)gmail(dot)com
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Signed vs. Unsigned (some)
Date: 2021-06-15 08:17:33
Message-ID: 20210615.171733.807705891321857575.horikyota.ntt@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

At Fri, 11 Jun 2021 23:05:29 -0300, Ranier Vilela <ranier(dot)vf(at)gmail(dot)com> wrote in
> Hi,
>
> Removing legitimate warnings can it be worth it?

From what the warning comes from? And what is the exact message?

> -1 CAST can be wrong, when there is an invalid value defined
> (InvalidBucket, InvalidBlockNumber).
> I think depending on the compiler -1 CAST may be different from
> InvalidBucket or InvalidBlockNumber.

The definitions are not ((type) -1) but ((type) 0xFFFFFFFF) so
actually they might be different if we forget to widen the constant
when widening the types. Regarding to the compiler behavior, I think
we are assuming C99[1] and C99 defines that -1 is converted to
Uxxx_MAX. (6.3.1.3 Singed and unsigned integers)

I'm +0.2 on it. It might be worthwhile as a matter of style.

> pg_rewind is one special case.
> All cases of XLogSegNo (uint64) initialization are zero, but in pg_rewind
> was used -1?
> I did not find it InvalidXLogSegNo!

I'm not sure whether that is a thinko that the variable is signed or
that it is intentional to assign the maximum value. Anyway, actually
there's no need for initializing the variable at all. So I don't think
it's worth changing the initial value. If any compiler actually
complains about the assignment changing it to zero seems reasonable.

> Not tested.
>
> Trivial patch attached.

Please don't quickly update the patch responding to my comments alone.
I might be a minority.

[1] http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1124.pdf

regards.

--
Kyotaro Horiguchi
NTT Open Source Software Center

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Michael Paquier 2021-06-15 09:01:18 Re: Error on pgbench logs
Previous Message Yugo NAGATA 2021-06-15 08:15:14 Re: Error on pgbench logs