Re: Cleanup shadows variable warnings, round 1 - Mailing list pgsql-hackers

From Peter Smith
Subject Re: Cleanup shadows variable warnings, round 1
Date
Msg-id CAHut+PvrcSUabnsuH+77+yEwvjiLHy0XJiLuTtVHWed_MHdwMw@mail.gmail.com
Whole thread Raw
In response to Re: Cleanup shadows variable warnings, round 1  (Chao Li <li.evan.chao@gmail.com>)
Responses Re: Cleanup shadows variable warnings, round 1
List pgsql-hackers
Hi Chao.

I always build with the shadow warnings enabled, so I am happy someone
has taken up the challenge to try to clean them up. You probably found
an old thread where I tried to do the same very thing several years
ago/. I had fixed most of them in my local environment, but the thread
became stalled due to
(a) IIUC, there was some push-back about causing too much churn, and
(b) I didn't know how to break it into manageable chunks.

So I wish you better luck this time. I have just started to look at
your patches:

======

Patch v2-0001.

src/backend/backup/basebackup_incremental.c:
PrepareForIncrementalBackup:

Instead of changing the var name from 'i' to 'u', you can fix this one
by changing all the for loops to declare 'i' within the 'for ('.
That way kills two birds with one stone: it removes the shadow warning
and at the same time improves the scope of the loop variables.


-       int                     i;

-       for (i = 0; i < num_wal_ranges; ++i)
+       for (int i = 0; i < num_wal_ranges; ++i)

-       for (i = 0; i < num_wal_ranges; ++i)
+       for (int i = 0; i < num_wal_ranges; ++i)

-       unsigned        i;

-               for (i = 0; i < nblocks; ++i)
+               for (unsigned i = 0; i < nblocks; ++i)


======

I will continue to look at the rest of the patches as time permits.

======
Kind Regards,
Peter Smith.
Fujitsu Australia



pgsql-hackers by date:

Previous
From: Richard Guo
Date:
Subject: Re: Some optimizations for COALESCE expressions during constant folding
Next
From: Chao Li
Date:
Subject: Re: Cleanup shadows variable warnings, round 1