Skip to content

Commit 421892a

Browse files
committed
Further reduce warnings with -Wshadow=compatible-local
In a similar effort to f01592f, 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
1 parent 869e56a commit 421892a

File tree

11 files changed

+22
-32
lines changed

11 files changed

+22
-32
lines changed

src/backend/access/brin/brin.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,6 @@ bringetbitmap(IndexScanDesc scan, TIDBitmap *tbm)
372372
**nullkeys;
373373
int *nkeys,
374374
*nnullkeys;
375-
int keyno;
376375
char *ptr;
377376
Size len;
378377
char *tmp PG_USED_FOR_ASSERTS_ONLY;
@@ -454,7 +453,7 @@ bringetbitmap(IndexScanDesc scan, TIDBitmap *tbm)
454453
memset(nnullkeys, 0, sizeof(int) * bdesc->bd_tupdesc->natts);
455454

456455
/* Preprocess the scan keys - split them into per-attribute arrays. */
457-
for (keyno = 0; keyno < scan->numberOfKeys; keyno++)
456+
for (int keyno = 0; keyno < scan->numberOfKeys; keyno++)
458457
{
459458
ScanKey key = &scan->keyData[keyno];
460459
AttrNumber keyattno = key->sk_attno;

src/backend/access/brin/brin_minmax_multi.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,6 @@ brin_range_serialize(Ranges *range)
582582
int typlen;
583583
bool typbyval;
584584

585-
int i;
586585
char *ptr;
587586

588587
/* simple sanity checks */
@@ -662,7 +661,7 @@ brin_range_serialize(Ranges *range)
662661
*/
663662
ptr = serialized->data; /* start of the serialized data */
664663

665-
for (i = 0; i < nvalues; i++)
664+
for (int i = 0; i < nvalues; i++)
666665
{
667666
if (typbyval) /* simple by-value data types */
668667
{

src/backend/access/gist/gist.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,6 @@ gistplacetopage(Relation rel, Size freespace, GISTSTATE *giststate,
234234
Page page = BufferGetPage(buffer);
235235
bool is_leaf = (GistPageIsLeaf(page)) ? true : false;
236236
XLogRecPtr recptr;
237-
int i;
238237
bool is_split;
239238

240239
/*
@@ -420,7 +419,7 @@ gistplacetopage(Relation rel, Size freespace, GISTSTATE *giststate,
420419
{
421420
char *data = (char *) (ptr->list);
422421

423-
for (i = 0; i < ptr->block.num; i++)
422+
for (int i = 0; i < ptr->block.num; i++)
424423
{
425424
IndexTuple thistup = (IndexTuple) data;
426425

src/backend/commands/copyfrom.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1202,7 +1202,6 @@ BeginCopyFrom(ParseState *pstate,
12021202
num_defaults;
12031203
FmgrInfo *in_functions;
12041204
Oid *typioparams;
1205-
int attnum;
12061205
Oid in_func_oid;
12071206
int *defmap;
12081207
ExprState **defexprs;
@@ -1401,7 +1400,7 @@ BeginCopyFrom(ParseState *pstate,
14011400
defmap = (int *) palloc(num_phys_attrs * sizeof(int));
14021401
defexprs = (ExprState **) palloc(num_phys_attrs * sizeof(ExprState *));
14031402

1404-
for (attnum = 1; attnum <= num_phys_attrs; attnum++)
1403+
for (int attnum = 1; attnum <= num_phys_attrs; attnum++)
14051404
{
14061405
Form_pg_attribute att = TupleDescAttr(tupDesc, attnum - 1);
14071406

src/backend/commands/indexcmds.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,6 @@ DefineIndex(Oid relationId,
565565
Oid root_save_userid;
566566
int root_save_sec_context;
567567
int root_save_nestlevel;
568-
int i;
569568

570569
root_save_nestlevel = NewGUCNestLevel();
571570

@@ -1047,7 +1046,7 @@ DefineIndex(Oid relationId,
10471046
* We disallow indexes on system columns. They would not necessarily get
10481047
* updated correctly, and they don't seem useful anyway.
10491048
*/
1050-
for (i = 0; i < indexInfo->ii_NumIndexAttrs; i++)
1049+
for (int i = 0; i < indexInfo->ii_NumIndexAttrs; i++)
10511050
{
10521051
AttrNumber attno = indexInfo->ii_IndexAttrNumbers[i];
10531052

@@ -1067,7 +1066,7 @@ DefineIndex(Oid relationId,
10671066
pull_varattnos((Node *) indexInfo->ii_Expressions, 1, &indexattrs);
10681067
pull_varattnos((Node *) indexInfo->ii_Predicate, 1, &indexattrs);
10691068

1070-
for (i = FirstLowInvalidHeapAttributeNumber + 1; i < 0; i++)
1069+
for (int i = FirstLowInvalidHeapAttributeNumber + 1; i < 0; i++)
10711070
{
10721071
if (bms_is_member(i - FirstLowInvalidHeapAttributeNumber,
10731072
indexattrs))
@@ -1243,7 +1242,7 @@ DefineIndex(Oid relationId,
12431242
* If none matches, build a new index by calling ourselves
12441243
* recursively with the same options (except for the index name).
12451244
*/
1246-
for (i = 0; i < nparts; i++)
1245+
for (int i = 0; i < nparts; i++)
12471246
{
12481247
Oid childRelid = part_oids[i];
12491248
Relation childrel;

src/backend/executor/nodeAgg.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1296,13 +1296,12 @@ finalize_aggregates(AggState *aggstate,
12961296
Datum *aggvalues = econtext->ecxt_aggvalues;
12971297
bool *aggnulls = econtext->ecxt_aggnulls;
12981298
int aggno;
1299-
int transno;
13001299

13011300
/*
13021301
* If there were any DISTINCT and/or ORDER BY aggregates, sort their
13031302
* inputs and run the transition functions.
13041303
*/
1305-
for (transno = 0; transno < aggstate->numtrans; transno++)
1304+
for (int transno = 0; transno < aggstate->numtrans; transno++)
13061305
{
13071306
AggStatePerTrans pertrans = &aggstate->pertrans[transno];
13081307
AggStatePerGroup pergroupstate;

src/backend/optimizer/path/costsize.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2447,7 +2447,6 @@ append_nonpartial_cost(List *subpaths, int numpaths, int parallel_workers)
24472447
int arrlen;
24482448
ListCell *l;
24492449
ListCell *cell;
2450-
int i;
24512450
int path_index;
24522451
int min_index;
24532452
int max_index;
@@ -2486,7 +2485,6 @@ append_nonpartial_cost(List *subpaths, int numpaths, int parallel_workers)
24862485
for_each_cell(l, subpaths, cell)
24872486
{
24882487
Path *subpath = (Path *) lfirst(l);
2489-
int i;
24902488

24912489
/* Consider only the non-partial paths */
24922490
if (path_index++ == numpaths)
@@ -2495,15 +2493,17 @@ append_nonpartial_cost(List *subpaths, int numpaths, int parallel_workers)
24952493
costarr[min_index] += subpath->total_cost;
24962494

24972495
/* Update the new min cost array index */
2498-
for (min_index = i = 0; i < arrlen; i++)
2496+
min_index = 0;
2497+
for (int i = 0; i < arrlen; i++)
24992498
{
25002499
if (costarr[i] < costarr[min_index])
25012500
min_index = i;
25022501
}
25032502
}
25042503

25052504
/* Return the highest cost from the array */
2506-
for (max_index = i = 0; i < arrlen; i++)
2505+
max_index = 0;
2506+
for (int i = 0; i < arrlen; i++)
25072507
{
25082508
if (costarr[i] > costarr[max_index])
25092509
max_index = i;

src/backend/statistics/mcv.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1604,7 +1604,6 @@ mcv_get_match_bitmap(PlannerInfo *root, List *clauses,
16041604
Bitmapset *keys, List *exprs,
16051605
MCVList *mcvlist, bool is_or)
16061606
{
1607-
int i;
16081607
ListCell *l;
16091608
bool *matches;
16101609

@@ -1659,7 +1658,7 @@ mcv_get_match_bitmap(PlannerInfo *root, List *clauses,
16591658
* can skip items that were already ruled out, and terminate if
16601659
* there are no remaining MCV items that might possibly match.
16611660
*/
1662-
for (i = 0; i < mcvlist->nitems; i++)
1661+
for (int i = 0; i < mcvlist->nitems; i++)
16631662
{
16641663
bool match = true;
16651664
MCVItem *item = &mcvlist->items[i];
@@ -1766,7 +1765,7 @@ mcv_get_match_bitmap(PlannerInfo *root, List *clauses,
17661765
* can skip items that were already ruled out, and terminate if
17671766
* there are no remaining MCV items that might possibly match.
17681767
*/
1769-
for (i = 0; i < mcvlist->nitems; i++)
1768+
for (int i = 0; i < mcvlist->nitems; i++)
17701769
{
17711770
int j;
17721771
bool match = !expr->useOr;
@@ -1837,7 +1836,7 @@ mcv_get_match_bitmap(PlannerInfo *root, List *clauses,
18371836
* can skip items that were already ruled out, and terminate if
18381837
* there are no remaining MCV items that might possibly match.
18391838
*/
1840-
for (i = 0; i < mcvlist->nitems; i++)
1839+
for (int i = 0; i < mcvlist->nitems; i++)
18411840
{
18421841
bool match = false; /* assume mismatch */
18431842
MCVItem *item = &mcvlist->items[i];
@@ -1930,7 +1929,7 @@ mcv_get_match_bitmap(PlannerInfo *root, List *clauses,
19301929
* can skip items that were already ruled out, and terminate if
19311930
* there are no remaining MCV items that might possibly match.
19321931
*/
1933-
for (i = 0; i < mcvlist->nitems; i++)
1932+
for (int i = 0; i < mcvlist->nitems; i++)
19341933
{
19351934
MCVItem *item = &mcvlist->items[i];
19361935
bool match = false;
@@ -1956,7 +1955,7 @@ mcv_get_match_bitmap(PlannerInfo *root, List *clauses,
19561955
* can skip items that were already ruled out, and terminate if
19571956
* there are no remaining MCV items that might possibly match.
19581957
*/
1959-
for (i = 0; i < mcvlist->nitems; i++)
1958+
for (int i = 0; i < mcvlist->nitems; i++)
19601959
{
19611960
bool match;
19621961
MCVItem *item = &mcvlist->items[i];

src/backend/storage/buffer/bufmgr.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3183,7 +3183,6 @@ void
31833183
DropRelationsAllBuffers(SMgrRelation *smgr_reln, int nlocators)
31843184
{
31853185
int i;
3186-
int j;
31873186
int n = 0;
31883187
SMgrRelation *rels;
31893188
BlockNumber (*block)[MAX_FORKNUM + 1];
@@ -3232,7 +3231,7 @@ DropRelationsAllBuffers(SMgrRelation *smgr_reln, int nlocators)
32323231
*/
32333232
for (i = 0; i < n && cached; i++)
32343233
{
3235-
for (j = 0; j <= MAX_FORKNUM; j++)
3234+
for (int j = 0; j <= MAX_FORKNUM; j++)
32363235
{
32373236
/* Get the number of blocks for a relation's fork. */
32383237
block[i][j] = smgrnblocks_cached(rels[i], j);
@@ -3259,7 +3258,7 @@ DropRelationsAllBuffers(SMgrRelation *smgr_reln, int nlocators)
32593258
{
32603259
for (i = 0; i < n; i++)
32613260
{
3262-
for (j = 0; j <= MAX_FORKNUM; j++)
3261+
for (int j = 0; j <= MAX_FORKNUM; j++)
32633262
{
32643263
/* ignore relation forks that doesn't exist */
32653264
if (!BlockNumberIsValid(block[i][j]))

src/bin/pg_dump/pg_dump.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11576,7 +11576,6 @@ dumpFunc(Archive *fout, const FuncInfo *finfo)
1157611576
char **configitems = NULL;
1157711577
int nconfigitems = 0;
1157811578
const char *keyword;
11579-
int i;
1158011579

1158111580
/* Do nothing in data-only dump */
1158211581
if (dopt->dataOnly)
@@ -11853,7 +11852,7 @@ dumpFunc(Archive *fout, const FuncInfo *finfo)
1185311852
finfo->dobj.name);
1185411853
}
1185511854

11856-
for (i = 0; i < nconfigitems; i++)
11855+
for (int i = 0; i < nconfigitems; i++)
1185711856
{
1185811857
/* we feel free to scribble on configitems[] here */
1185911858
char *configitem = configitems[i];

src/interfaces/ecpg/pgtypeslib/numeric.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,7 +1062,6 @@ PGTYPESnumeric_div(numeric *var1, numeric *var2, numeric *result)
10621062
int weight_tmp;
10631063
int rscale_tmp;
10641064
int ri;
1065-
int i;
10661065
long guess;
10671066
long first_have;
10681067
long first_div;
@@ -1109,7 +1108,7 @@ PGTYPESnumeric_div(numeric *var1, numeric *var2, numeric *result)
11091108
* Initialize local variables
11101109
*/
11111110
init_var(&dividend);
1112-
for (i = 1; i < 10; i++)
1111+
for (int i = 1; i < 10; i++)
11131112
init_var(&divisor[i]);
11141113

11151114
/*
@@ -1268,7 +1267,7 @@ PGTYPESnumeric_div(numeric *var1, numeric *var2, numeric *result)
12681267
if (dividend.buf != NULL)
12691268
digitbuf_free(dividend.buf);
12701269

1271-
for (i = 1; i < 10; i++)
1270+
for (int i = 1; i < 10; i++)
12721271
{
12731272
if (divisor[i].buf != NULL)
12741273
digitbuf_free(divisor[i].buf);

0 commit comments

Comments
 (0)