From: Álvaro Herrera Date: Tue, 3 Mar 2026 10:19:23 +0000 (+0100) Subject: Reduce scope of for-loop-local variables to avoid shadowing X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=cece37c9843c980b5be2f6d24c2b9cef1f9429a7;p=thirdparty%2Fpostgresql.git 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 Reviewed-by: Peter Smith Reviewed-by: Álvaro Herrera Discussion: https://postgr.es/m/CAEoWx2kQ2x5gMaj8tHLJ3=jfC+p5YXHkJyHrDTiQw2nn2FJTmQ@mail.gmail.com --- diff --git a/src/backend/backup/basebackup_incremental.c b/src/backend/backup/basebackup_incremental.c index f58ed9b198a..6f3552c6a4a 100644 --- a/src/backend/backup/basebackup_incremental.c +++ b/src/backend/backup/basebackup_incremental.c @@ -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]); } diff --git a/src/backend/parser/parse_target.c b/src/backend/parser/parse_target.c index dbf5b2b5c01..3bcfc1f5e3d 100644 --- a/src/backend/parser/parse_target.c +++ b/src/backend/parser/parse_target.c @@ -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;