]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Reduce scope of for-loop-local variables to avoid shadowing
authorÁlvaro Herrera <alvherre@kurilemu.de>
Tue, 3 Mar 2026 10:19:23 +0000 (11:19 +0100)
committerÁlvaro Herrera <alvherre@kurilemu.de>
Tue, 3 Mar 2026 10:24:11 +0000 (11:24 +0100)
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

src/backend/backup/basebackup_incremental.c
src/backend/parser/parse_target.c

index f58ed9b198a48ec519da0575e4db19ae8e6e8244..6f3552c6a4a542ab85e8a4b6b4798ccf5897022f 100644 (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]);
                        }
index dbf5b2b5c01ca5fa258f15a03215fbf36e36afa4..3bcfc1f5e3db5357bb6e818308a79d651339fcfe 100644 (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;