Reduce scope of for-loop-local variables to avoid shadowing

Adjust a couple of for-loops where a local variable was shadowed by
another in the same scope, by renaming it as well as reducing its scope
to the containing for-loop.

Author: Chao Li <lic@highgo.com>
Reviewed-by: Peter Smith <smithpb2250@gmail.com>
Reviewed-by: Álvaro Herrera <alvherre@kurilemu.de>
Discussion: https://postgr.es/m/CAEoWx2kQ2x5gMaj8tHLJ3=jfC+p5YXHkJyHrDTiQw2nn2FJTmQ@mail.gmail.com
This commit is contained in:
Álvaro Herrera 2026-03-03 11:19:23 +01:00
parent f2d7570cdd
commit cece37c984
No known key found for this signature in database
GPG key ID: 1C20ACB9D5C564AE
2 changed files with 8 additions and 12 deletions

View file

@ -270,7 +270,6 @@ PrepareForIncrementalBackup(IncrementalBackupInfo *ib,
ListCell *lc;
TimeLineHistoryEntry **tlep;
int num_wal_ranges;
int i;
bool found_backup_start_tli = false;
TimeLineID earliest_wal_range_tli = 0;
XLogRecPtr earliest_wal_range_start_lsn = InvalidXLogRecPtr;
@ -312,7 +311,7 @@ PrepareForIncrementalBackup(IncrementalBackupInfo *ib,
*/
expectedTLEs = readTimeLineHistory(backup_state->starttli);
tlep = palloc0(num_wal_ranges * sizeof(TimeLineHistoryEntry *));
for (i = 0; i < num_wal_ranges; ++i)
for (int i = 0; i < num_wal_ranges; ++i)
{
backup_wal_range *range = list_nth(ib->manifest_wal_ranges, i);
bool saw_earliest_wal_range_tli = false;
@ -400,7 +399,7 @@ PrepareForIncrementalBackup(IncrementalBackupInfo *ib,
* anything here. However, if there's a problem staring us right in the
* face, it's best to report it, so we do.
*/
for (i = 0; i < num_wal_ranges; ++i)
for (int i = 0; i < num_wal_ranges; ++i)
{
backup_wal_range *range = list_nth(ib->manifest_wal_ranges, i);
@ -595,15 +594,14 @@ PrepareForIncrementalBackup(IncrementalBackupInfo *ib,
while (1)
{
unsigned nblocks;
unsigned i;
unsigned int nblocks;
nblocks = BlockRefTableReaderGetBlocks(reader, blocks,
BLOCKS_PER_READ);
if (nblocks == 0)
break;
for (i = 0; i < nblocks; ++i)
for (unsigned int i = 0; i < nblocks; ++i)
BlockRefTableMarkBlockModified(ib->brtab, &rlocator,
forknum, blocks[i]);
}

View file

@ -1611,10 +1611,9 @@ expandRecordVariable(ParseState *pstate, Var *var, int levelsup)
* subselect must have that outer level as parent.
*/
ParseState mypstate = {0};
Index levelsup;
/* this loop must work, since GetRTEByRangeTablePosn did */
for (levelsup = 0; levelsup < netlevelsup; levelsup++)
for (Index level = 0; level < netlevelsup; level++)
pstate = pstate->parentParseState;
mypstate.parentParseState = pstate;
mypstate.p_rtable = rte->subquery->rtable;
@ -1669,12 +1668,11 @@ expandRecordVariable(ParseState *pstate, Var *var, int levelsup)
* could be an outer CTE (compare SUBQUERY case above).
*/
ParseState mypstate = {0};
Index levelsup;
/* this loop must work, since GetCTEForRTE did */
for (levelsup = 0;
levelsup < rte->ctelevelsup + netlevelsup;
levelsup++)
for (Index level = 0;
level < rte->ctelevelsup + netlevelsup;
level++)
pstate = pstate->parentParseState;
mypstate.parentParseState = pstate;
mypstate.p_rtable = ((Query *) cte->ctequery)->rtable;