diff options
| author | David Rowley <drowley@postgresql.org> | 2022-08-24 12:27:12 +1200 |
|---|---|---|
| committer | David Rowley <drowley@postgresql.org> | 2022-08-24 12:27:12 +1200 |
| commit | 421892a192b8f95ab96c5edb61d424f80a4221d0 (patch) | |
| tree | 74b077cee1c0c21fef0faec5ff0a63d050f991ca /src/backend/optimizer/path | |
| parent | 869e56a39976a42a393adc2d69df3abce7eff18f (diff) | |
Further reduce warnings with -Wshadow=compatible-local
In a similar effort to f01592f91, here we're targetting fixing the
warnings that -Wshadow=compatible-local produces that we can fix by moving
a variable to an inner scope to stop that variable from being shadowed by
another variable declared somewhere later in the function.
All of the warnings being fixed here are changing the scope of variables
which are being used as an iterator for a "for" loop. In each instance,
the fix happens to be changing the for loop to use the C99 type
initialization. Much of this code likely pre-dates our use of C99.
Reducing the scope of the outer scoped variable seems like the safest way
to fix these. Renaming seems more likely to risk patches using the wrong
variable. Reducing the scope is more likely to result in a compilation
failure after applying some future patch rather than introducing bugs with
it.
By my count, this takes the warning count from 129 down to 114.
Author: Justin Pryzby
Discussion: https://postgr.es/m/CAApHDvrwLGBP%2BYw9vriayyf%3DXR4uPWP5jr6cQhP9au_kaDUhbA%40mail.gmail.com
Diffstat (limited to 'src/backend/optimizer/path')
| -rw-r--r-- | src/backend/optimizer/path/costsize.c | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/src/backend/optimizer/path/costsize.c b/src/backend/optimizer/path/costsize.c index 1e94c5aa7c4..75acea149c7 100644 --- a/src/backend/optimizer/path/costsize.c +++ b/src/backend/optimizer/path/costsize.c @@ -2447,7 +2447,6 @@ append_nonpartial_cost(List *subpaths, int numpaths, int parallel_workers) int arrlen; ListCell *l; ListCell *cell; - int i; int path_index; int min_index; int max_index; @@ -2486,7 +2485,6 @@ append_nonpartial_cost(List *subpaths, int numpaths, int parallel_workers) for_each_cell(l, subpaths, cell) { Path *subpath = (Path *) lfirst(l); - int i; /* Consider only the non-partial paths */ if (path_index++ == numpaths) @@ -2495,7 +2493,8 @@ append_nonpartial_cost(List *subpaths, int numpaths, int parallel_workers) costarr[min_index] += subpath->total_cost; /* Update the new min cost array index */ - for (min_index = i = 0; i < arrlen; i++) + min_index = 0; + for (int i = 0; i < arrlen; i++) { if (costarr[i] < costarr[min_index]) min_index = i; @@ -2503,7 +2502,8 @@ append_nonpartial_cost(List *subpaths, int numpaths, int parallel_workers) } /* Return the highest cost from the array */ - for (max_index = i = 0; i < arrlen; i++) + max_index = 0; + for (int i = 0; i < arrlen; i++) { if (costarr[i] > costarr[max_index]) max_index = i; |
