Re: Cleanup shadows variable warnings, round 1

Поиск
Список
Период
Сортировка
От Álvaro Herrera
Тема Re: Cleanup shadows variable warnings, round 1
Дата
Msg-id 202512031432.cpvnk5irwygr@alvherre.pgsql
обсуждение исходный текст
Ответ на Re: Cleanup shadows variable warnings, round 1  (Chao Li <li.evan.chao@gmail.com>)
Ответы Re: Cleanup shadows variable warnings, round 1
Список 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/



В списке pgsql-hackers по дате отправления: