mirror of
https://github.com/postgres/postgres.git
synced 2025-04-27 22:56:53 +03:00
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
This commit is contained in:
parent
869e56a399
commit
421892a192
@ -372,7 +372,6 @@ bringetbitmap(IndexScanDesc scan, TIDBitmap *tbm)
|
|||||||
**nullkeys;
|
**nullkeys;
|
||||||
int *nkeys,
|
int *nkeys,
|
||||||
*nnullkeys;
|
*nnullkeys;
|
||||||
int keyno;
|
|
||||||
char *ptr;
|
char *ptr;
|
||||||
Size len;
|
Size len;
|
||||||
char *tmp PG_USED_FOR_ASSERTS_ONLY;
|
char *tmp PG_USED_FOR_ASSERTS_ONLY;
|
||||||
@ -454,7 +453,7 @@ bringetbitmap(IndexScanDesc scan, TIDBitmap *tbm)
|
|||||||
memset(nnullkeys, 0, sizeof(int) * bdesc->bd_tupdesc->natts);
|
memset(nnullkeys, 0, sizeof(int) * bdesc->bd_tupdesc->natts);
|
||||||
|
|
||||||
/* Preprocess the scan keys - split them into per-attribute arrays. */
|
/* Preprocess the scan keys - split them into per-attribute arrays. */
|
||||||
for (keyno = 0; keyno < scan->numberOfKeys; keyno++)
|
for (int keyno = 0; keyno < scan->numberOfKeys; keyno++)
|
||||||
{
|
{
|
||||||
ScanKey key = &scan->keyData[keyno];
|
ScanKey key = &scan->keyData[keyno];
|
||||||
AttrNumber keyattno = key->sk_attno;
|
AttrNumber keyattno = key->sk_attno;
|
||||||
|
@ -582,7 +582,6 @@ brin_range_serialize(Ranges *range)
|
|||||||
int typlen;
|
int typlen;
|
||||||
bool typbyval;
|
bool typbyval;
|
||||||
|
|
||||||
int i;
|
|
||||||
char *ptr;
|
char *ptr;
|
||||||
|
|
||||||
/* simple sanity checks */
|
/* simple sanity checks */
|
||||||
@ -662,7 +661,7 @@ brin_range_serialize(Ranges *range)
|
|||||||
*/
|
*/
|
||||||
ptr = serialized->data; /* start of the serialized data */
|
ptr = serialized->data; /* start of the serialized data */
|
||||||
|
|
||||||
for (i = 0; i < nvalues; i++)
|
for (int i = 0; i < nvalues; i++)
|
||||||
{
|
{
|
||||||
if (typbyval) /* simple by-value data types */
|
if (typbyval) /* simple by-value data types */
|
||||||
{
|
{
|
||||||
|
@ -234,7 +234,6 @@ gistplacetopage(Relation rel, Size freespace, GISTSTATE *giststate,
|
|||||||
Page page = BufferGetPage(buffer);
|
Page page = BufferGetPage(buffer);
|
||||||
bool is_leaf = (GistPageIsLeaf(page)) ? true : false;
|
bool is_leaf = (GistPageIsLeaf(page)) ? true : false;
|
||||||
XLogRecPtr recptr;
|
XLogRecPtr recptr;
|
||||||
int i;
|
|
||||||
bool is_split;
|
bool is_split;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -420,7 +419,7 @@ gistplacetopage(Relation rel, Size freespace, GISTSTATE *giststate,
|
|||||||
{
|
{
|
||||||
char *data = (char *) (ptr->list);
|
char *data = (char *) (ptr->list);
|
||||||
|
|
||||||
for (i = 0; i < ptr->block.num; i++)
|
for (int i = 0; i < ptr->block.num; i++)
|
||||||
{
|
{
|
||||||
IndexTuple thistup = (IndexTuple) data;
|
IndexTuple thistup = (IndexTuple) data;
|
||||||
|
|
||||||
|
@ -1202,7 +1202,6 @@ BeginCopyFrom(ParseState *pstate,
|
|||||||
num_defaults;
|
num_defaults;
|
||||||
FmgrInfo *in_functions;
|
FmgrInfo *in_functions;
|
||||||
Oid *typioparams;
|
Oid *typioparams;
|
||||||
int attnum;
|
|
||||||
Oid in_func_oid;
|
Oid in_func_oid;
|
||||||
int *defmap;
|
int *defmap;
|
||||||
ExprState **defexprs;
|
ExprState **defexprs;
|
||||||
@ -1401,7 +1400,7 @@ BeginCopyFrom(ParseState *pstate,
|
|||||||
defmap = (int *) palloc(num_phys_attrs * sizeof(int));
|
defmap = (int *) palloc(num_phys_attrs * sizeof(int));
|
||||||
defexprs = (ExprState **) palloc(num_phys_attrs * sizeof(ExprState *));
|
defexprs = (ExprState **) palloc(num_phys_attrs * sizeof(ExprState *));
|
||||||
|
|
||||||
for (attnum = 1; attnum <= num_phys_attrs; attnum++)
|
for (int attnum = 1; attnum <= num_phys_attrs; attnum++)
|
||||||
{
|
{
|
||||||
Form_pg_attribute att = TupleDescAttr(tupDesc, attnum - 1);
|
Form_pg_attribute att = TupleDescAttr(tupDesc, attnum - 1);
|
||||||
|
|
||||||
|
@ -565,7 +565,6 @@ DefineIndex(Oid relationId,
|
|||||||
Oid root_save_userid;
|
Oid root_save_userid;
|
||||||
int root_save_sec_context;
|
int root_save_sec_context;
|
||||||
int root_save_nestlevel;
|
int root_save_nestlevel;
|
||||||
int i;
|
|
||||||
|
|
||||||
root_save_nestlevel = NewGUCNestLevel();
|
root_save_nestlevel = NewGUCNestLevel();
|
||||||
|
|
||||||
@ -1047,7 +1046,7 @@ DefineIndex(Oid relationId,
|
|||||||
* We disallow indexes on system columns. They would not necessarily get
|
* We disallow indexes on system columns. They would not necessarily get
|
||||||
* updated correctly, and they don't seem useful anyway.
|
* updated correctly, and they don't seem useful anyway.
|
||||||
*/
|
*/
|
||||||
for (i = 0; i < indexInfo->ii_NumIndexAttrs; i++)
|
for (int i = 0; i < indexInfo->ii_NumIndexAttrs; i++)
|
||||||
{
|
{
|
||||||
AttrNumber attno = indexInfo->ii_IndexAttrNumbers[i];
|
AttrNumber attno = indexInfo->ii_IndexAttrNumbers[i];
|
||||||
|
|
||||||
@ -1067,7 +1066,7 @@ DefineIndex(Oid relationId,
|
|||||||
pull_varattnos((Node *) indexInfo->ii_Expressions, 1, &indexattrs);
|
pull_varattnos((Node *) indexInfo->ii_Expressions, 1, &indexattrs);
|
||||||
pull_varattnos((Node *) indexInfo->ii_Predicate, 1, &indexattrs);
|
pull_varattnos((Node *) indexInfo->ii_Predicate, 1, &indexattrs);
|
||||||
|
|
||||||
for (i = FirstLowInvalidHeapAttributeNumber + 1; i < 0; i++)
|
for (int i = FirstLowInvalidHeapAttributeNumber + 1; i < 0; i++)
|
||||||
{
|
{
|
||||||
if (bms_is_member(i - FirstLowInvalidHeapAttributeNumber,
|
if (bms_is_member(i - FirstLowInvalidHeapAttributeNumber,
|
||||||
indexattrs))
|
indexattrs))
|
||||||
@ -1243,7 +1242,7 @@ DefineIndex(Oid relationId,
|
|||||||
* If none matches, build a new index by calling ourselves
|
* If none matches, build a new index by calling ourselves
|
||||||
* recursively with the same options (except for the index name).
|
* recursively with the same options (except for the index name).
|
||||||
*/
|
*/
|
||||||
for (i = 0; i < nparts; i++)
|
for (int i = 0; i < nparts; i++)
|
||||||
{
|
{
|
||||||
Oid childRelid = part_oids[i];
|
Oid childRelid = part_oids[i];
|
||||||
Relation childrel;
|
Relation childrel;
|
||||||
|
@ -1296,13 +1296,12 @@ finalize_aggregates(AggState *aggstate,
|
|||||||
Datum *aggvalues = econtext->ecxt_aggvalues;
|
Datum *aggvalues = econtext->ecxt_aggvalues;
|
||||||
bool *aggnulls = econtext->ecxt_aggnulls;
|
bool *aggnulls = econtext->ecxt_aggnulls;
|
||||||
int aggno;
|
int aggno;
|
||||||
int transno;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If there were any DISTINCT and/or ORDER BY aggregates, sort their
|
* If there were any DISTINCT and/or ORDER BY aggregates, sort their
|
||||||
* inputs and run the transition functions.
|
* inputs and run the transition functions.
|
||||||
*/
|
*/
|
||||||
for (transno = 0; transno < aggstate->numtrans; transno++)
|
for (int transno = 0; transno < aggstate->numtrans; transno++)
|
||||||
{
|
{
|
||||||
AggStatePerTrans pertrans = &aggstate->pertrans[transno];
|
AggStatePerTrans pertrans = &aggstate->pertrans[transno];
|
||||||
AggStatePerGroup pergroupstate;
|
AggStatePerGroup pergroupstate;
|
||||||
|
@ -2447,7 +2447,6 @@ append_nonpartial_cost(List *subpaths, int numpaths, int parallel_workers)
|
|||||||
int arrlen;
|
int arrlen;
|
||||||
ListCell *l;
|
ListCell *l;
|
||||||
ListCell *cell;
|
ListCell *cell;
|
||||||
int i;
|
|
||||||
int path_index;
|
int path_index;
|
||||||
int min_index;
|
int min_index;
|
||||||
int max_index;
|
int max_index;
|
||||||
@ -2486,7 +2485,6 @@ append_nonpartial_cost(List *subpaths, int numpaths, int parallel_workers)
|
|||||||
for_each_cell(l, subpaths, cell)
|
for_each_cell(l, subpaths, cell)
|
||||||
{
|
{
|
||||||
Path *subpath = (Path *) lfirst(l);
|
Path *subpath = (Path *) lfirst(l);
|
||||||
int i;
|
|
||||||
|
|
||||||
/* Consider only the non-partial paths */
|
/* Consider only the non-partial paths */
|
||||||
if (path_index++ == numpaths)
|
if (path_index++ == numpaths)
|
||||||
@ -2495,7 +2493,8 @@ append_nonpartial_cost(List *subpaths, int numpaths, int parallel_workers)
|
|||||||
costarr[min_index] += subpath->total_cost;
|
costarr[min_index] += subpath->total_cost;
|
||||||
|
|
||||||
/* Update the new min cost array index */
|
/* 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])
|
if (costarr[i] < costarr[min_index])
|
||||||
min_index = i;
|
min_index = i;
|
||||||
@ -2503,7 +2502,8 @@ append_nonpartial_cost(List *subpaths, int numpaths, int parallel_workers)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Return the highest cost from the array */
|
/* 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])
|
if (costarr[i] > costarr[max_index])
|
||||||
max_index = i;
|
max_index = i;
|
||||||
|
@ -1604,7 +1604,6 @@ mcv_get_match_bitmap(PlannerInfo *root, List *clauses,
|
|||||||
Bitmapset *keys, List *exprs,
|
Bitmapset *keys, List *exprs,
|
||||||
MCVList *mcvlist, bool is_or)
|
MCVList *mcvlist, bool is_or)
|
||||||
{
|
{
|
||||||
int i;
|
|
||||||
ListCell *l;
|
ListCell *l;
|
||||||
bool *matches;
|
bool *matches;
|
||||||
|
|
||||||
@ -1659,7 +1658,7 @@ mcv_get_match_bitmap(PlannerInfo *root, List *clauses,
|
|||||||
* can skip items that were already ruled out, and terminate if
|
* can skip items that were already ruled out, and terminate if
|
||||||
* there are no remaining MCV items that might possibly match.
|
* there are no remaining MCV items that might possibly match.
|
||||||
*/
|
*/
|
||||||
for (i = 0; i < mcvlist->nitems; i++)
|
for (int i = 0; i < mcvlist->nitems; i++)
|
||||||
{
|
{
|
||||||
bool match = true;
|
bool match = true;
|
||||||
MCVItem *item = &mcvlist->items[i];
|
MCVItem *item = &mcvlist->items[i];
|
||||||
@ -1766,7 +1765,7 @@ mcv_get_match_bitmap(PlannerInfo *root, List *clauses,
|
|||||||
* can skip items that were already ruled out, and terminate if
|
* can skip items that were already ruled out, and terminate if
|
||||||
* there are no remaining MCV items that might possibly match.
|
* there are no remaining MCV items that might possibly match.
|
||||||
*/
|
*/
|
||||||
for (i = 0; i < mcvlist->nitems; i++)
|
for (int i = 0; i < mcvlist->nitems; i++)
|
||||||
{
|
{
|
||||||
int j;
|
int j;
|
||||||
bool match = !expr->useOr;
|
bool match = !expr->useOr;
|
||||||
@ -1837,7 +1836,7 @@ mcv_get_match_bitmap(PlannerInfo *root, List *clauses,
|
|||||||
* can skip items that were already ruled out, and terminate if
|
* can skip items that were already ruled out, and terminate if
|
||||||
* there are no remaining MCV items that might possibly match.
|
* there are no remaining MCV items that might possibly match.
|
||||||
*/
|
*/
|
||||||
for (i = 0; i < mcvlist->nitems; i++)
|
for (int i = 0; i < mcvlist->nitems; i++)
|
||||||
{
|
{
|
||||||
bool match = false; /* assume mismatch */
|
bool match = false; /* assume mismatch */
|
||||||
MCVItem *item = &mcvlist->items[i];
|
MCVItem *item = &mcvlist->items[i];
|
||||||
@ -1930,7 +1929,7 @@ mcv_get_match_bitmap(PlannerInfo *root, List *clauses,
|
|||||||
* can skip items that were already ruled out, and terminate if
|
* can skip items that were already ruled out, and terminate if
|
||||||
* there are no remaining MCV items that might possibly match.
|
* there are no remaining MCV items that might possibly match.
|
||||||
*/
|
*/
|
||||||
for (i = 0; i < mcvlist->nitems; i++)
|
for (int i = 0; i < mcvlist->nitems; i++)
|
||||||
{
|
{
|
||||||
MCVItem *item = &mcvlist->items[i];
|
MCVItem *item = &mcvlist->items[i];
|
||||||
bool match = false;
|
bool match = false;
|
||||||
@ -1956,7 +1955,7 @@ mcv_get_match_bitmap(PlannerInfo *root, List *clauses,
|
|||||||
* can skip items that were already ruled out, and terminate if
|
* can skip items that were already ruled out, and terminate if
|
||||||
* there are no remaining MCV items that might possibly match.
|
* there are no remaining MCV items that might possibly match.
|
||||||
*/
|
*/
|
||||||
for (i = 0; i < mcvlist->nitems; i++)
|
for (int i = 0; i < mcvlist->nitems; i++)
|
||||||
{
|
{
|
||||||
bool match;
|
bool match;
|
||||||
MCVItem *item = &mcvlist->items[i];
|
MCVItem *item = &mcvlist->items[i];
|
||||||
|
@ -3183,7 +3183,6 @@ void
|
|||||||
DropRelationsAllBuffers(SMgrRelation *smgr_reln, int nlocators)
|
DropRelationsAllBuffers(SMgrRelation *smgr_reln, int nlocators)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
int j;
|
|
||||||
int n = 0;
|
int n = 0;
|
||||||
SMgrRelation *rels;
|
SMgrRelation *rels;
|
||||||
BlockNumber (*block)[MAX_FORKNUM + 1];
|
BlockNumber (*block)[MAX_FORKNUM + 1];
|
||||||
@ -3232,7 +3231,7 @@ DropRelationsAllBuffers(SMgrRelation *smgr_reln, int nlocators)
|
|||||||
*/
|
*/
|
||||||
for (i = 0; i < n && cached; i++)
|
for (i = 0; i < n && cached; i++)
|
||||||
{
|
{
|
||||||
for (j = 0; j <= MAX_FORKNUM; j++)
|
for (int j = 0; j <= MAX_FORKNUM; j++)
|
||||||
{
|
{
|
||||||
/* Get the number of blocks for a relation's fork. */
|
/* Get the number of blocks for a relation's fork. */
|
||||||
block[i][j] = smgrnblocks_cached(rels[i], j);
|
block[i][j] = smgrnblocks_cached(rels[i], j);
|
||||||
@ -3259,7 +3258,7 @@ DropRelationsAllBuffers(SMgrRelation *smgr_reln, int nlocators)
|
|||||||
{
|
{
|
||||||
for (i = 0; i < n; i++)
|
for (i = 0; i < n; i++)
|
||||||
{
|
{
|
||||||
for (j = 0; j <= MAX_FORKNUM; j++)
|
for (int j = 0; j <= MAX_FORKNUM; j++)
|
||||||
{
|
{
|
||||||
/* ignore relation forks that doesn't exist */
|
/* ignore relation forks that doesn't exist */
|
||||||
if (!BlockNumberIsValid(block[i][j]))
|
if (!BlockNumberIsValid(block[i][j]))
|
||||||
|
@ -11576,7 +11576,6 @@ dumpFunc(Archive *fout, const FuncInfo *finfo)
|
|||||||
char **configitems = NULL;
|
char **configitems = NULL;
|
||||||
int nconfigitems = 0;
|
int nconfigitems = 0;
|
||||||
const char *keyword;
|
const char *keyword;
|
||||||
int i;
|
|
||||||
|
|
||||||
/* Do nothing in data-only dump */
|
/* Do nothing in data-only dump */
|
||||||
if (dopt->dataOnly)
|
if (dopt->dataOnly)
|
||||||
@ -11853,7 +11852,7 @@ dumpFunc(Archive *fout, const FuncInfo *finfo)
|
|||||||
finfo->dobj.name);
|
finfo->dobj.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < nconfigitems; i++)
|
for (int i = 0; i < nconfigitems; i++)
|
||||||
{
|
{
|
||||||
/* we feel free to scribble on configitems[] here */
|
/* we feel free to scribble on configitems[] here */
|
||||||
char *configitem = configitems[i];
|
char *configitem = configitems[i];
|
||||||
|
@ -1062,7 +1062,6 @@ PGTYPESnumeric_div(numeric *var1, numeric *var2, numeric *result)
|
|||||||
int weight_tmp;
|
int weight_tmp;
|
||||||
int rscale_tmp;
|
int rscale_tmp;
|
||||||
int ri;
|
int ri;
|
||||||
int i;
|
|
||||||
long guess;
|
long guess;
|
||||||
long first_have;
|
long first_have;
|
||||||
long first_div;
|
long first_div;
|
||||||
@ -1109,7 +1108,7 @@ PGTYPESnumeric_div(numeric *var1, numeric *var2, numeric *result)
|
|||||||
* Initialize local variables
|
* Initialize local variables
|
||||||
*/
|
*/
|
||||||
init_var(÷nd);
|
init_var(÷nd);
|
||||||
for (i = 1; i < 10; i++)
|
for (int i = 1; i < 10; i++)
|
||||||
init_var(&divisor[i]);
|
init_var(&divisor[i]);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -1268,7 +1267,7 @@ done:
|
|||||||
if (dividend.buf != NULL)
|
if (dividend.buf != NULL)
|
||||||
digitbuf_free(dividend.buf);
|
digitbuf_free(dividend.buf);
|
||||||
|
|
||||||
for (i = 1; i < 10; i++)
|
for (int i = 1; i < 10; i++)
|
||||||
{
|
{
|
||||||
if (divisor[i].buf != NULL)
|
if (divisor[i].buf != NULL)
|
||||||
digitbuf_free(divisor[i].buf);
|
digitbuf_free(divisor[i].buf);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user