Re: Signed vs. Unsigned (some) - Mailing list pgsql-hackers

From Peter Eisentraut
Subject Re: Signed vs. Unsigned (some)
Date
Msg-id 21052764-1e9e-7eeb-753f-ab47c3400249@enterprisedb.com
Whole thread Raw
In response to Re: Signed vs. Unsigned (some)  (Kyotaro Horiguchi <horikyota.ntt@gmail.com>)
Responses Re: Signed vs. Unsigned (some)
Re: Signed vs. Unsigned (some)
List pgsql-hackers
On 15.06.21 10:17, Kyotaro Horiguchi wrote:
> 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.

I think since we have the constants we should use them.

>> 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.

I think this case needs some analysis and explanation what is going on. 
I agree that the existing code looks a bit fishy, but we shouldn't just 
change it to something else without understanding what is going on.



pgsql-hackers by date:

Previous
From: Kyotaro Horiguchi
Date:
Subject: Re: detailed error message of pg_waldump
Next
From: Heikki Linnakangas
Date:
Subject: Re: Different compression methods for FPI