Re: Cleanup shadows variable warnings, round 1
Álvaro Herrera <alvherre@kurilemu.de>
From: Álvaro Herrera <alvherre@kurilemu.de>
To: Chao Li <li.evan.chao@gmail.com>
Cc: Peter Smith <smithpb2250@gmail.com>, Peter Eisentraut <peter@eisentraut.org>,
Postgres hackers <pgsql-hackers@lists.postgresql.org>
Date: 2025-12-03T14:36:05Z
Lists: pgsql-hackers
On 2025-Dec-03, Chao Li wrote:
> Unfortunately that doesn’t work for my compiler (clang on MacOS),
> that’s why I renamed “I" to “u”.
I think you're missing his point. He's suggesting to change not only
this variable, but also the other uses of "i" in this function.
I'd also change "unsigned" to "unsigned int", just because I dislike
using unadorned "unsigned" as a type name (I know it's a legal type
name.) This could be left alone, I guess -- not important.
diff --git a/src/backend/backup/basebackup_incremental.c b/src/backend/backup/basebackup_incremental.c
index 852ab577045..322d8997400 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]);
}
--
Álvaro Herrera PostgreSQL Developer — https://www.EnterpriseDB.com/
Commits
Same data as JSON:
GET /api/v1/messages/:b64id/commits
the thread's linked commits as JSON, with link sources.
API reference →
-
Fix new-to-v19 -Wshadow warnings
- 4f0cbc6fb5df 19 (unreleased) landed
-
Reduce scope of for-loop-local variables to avoid shadowing
- cece37c9843c 19 (unreleased) landed
-
Fix local-variable shadowing in pg_trgm's printSourceNFA().
- cdaa67565867 19 (unreleased) cited