Re: for loop variable fixes - Mailing list pgsql-hackers

From Peter Eisentraut
Subject Re: for loop variable fixes
Date
Msg-id 690a2546-e981-4b8b-b4e0-270542f51c9d@eisentraut.org
Whole thread
List pgsql-hackers
On 23.06.26 16:12, Tom Lane wrote:
> Peter Eisentraut <peter@eisentraut.org> writes:
>> I have noticed that many for loops have loop variables whose type
>> doesn't match the upper-bound condition.  Meaning, if you have
>>       for (i = 0; i < foo; i++)
>> then the type of i should ordinarily be the same as the type of foo.
> 
> +1 for improving this --- I was annoyed about it just yesterday
> with respect to resowner.c.  It looks to me like just about every
> single instance of "for (int ..." in that file is wrong because
> what's being compared to is unsigned.  I see that your patch gets
> a couple of those places, but only a couple, which makes me wonder
> what -Wsign-compare is checking exactly.
> 
>> As far as I can tell, none of of these are current bugs, but this is the
>> kind of thing that sets bad precedents and could lead to truncated
>> values or unintended overflows etc. in the future.
> 
> Right.  For resowner.c, I don't think the compared-to values can
> actually reach INT_MAX, but that doesn't make this good code.

This has been committed.




pgsql-hackers by date:

Previous
From: "ZizhuanLiu X-MAN"
Date:
Subject: Re: support create index on virtual generated column.
Next
From: "cca5507"
Date:
Subject: Re: Do not lock tables in get_tables_to_repack