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
**nullkeys;
int *nkeys,
*nnullkeys;
- int keyno;
char *ptr;
Size len;
char *tmp PG_USED_FOR_ASSERTS_ONLY;
memset(nnullkeys, 0, sizeof(int) * bdesc->bd_tupdesc->natts);
/* 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];
AttrNumber keyattno = key->sk_attno;
int typlen;
bool typbyval;
- int i;
char *ptr;
/* simple sanity checks */
*/
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 */
{
Page page = BufferGetPage(buffer);
bool is_leaf = (GistPageIsLeaf(page)) ? true : false;
XLogRecPtr recptr;
- int i;
bool is_split;
/*
{
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;
num_defaults;
FmgrInfo *in_functions;
Oid *typioparams;
- int attnum;
Oid in_func_oid;
int *defmap;
ExprState **defexprs;
defmap = (int *) palloc(num_phys_attrs * sizeof(int));
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);
Oid root_save_userid;
int root_save_sec_context;
int root_save_nestlevel;
- int i;
root_save_nestlevel = NewGUCNestLevel();
* We disallow indexes on system columns. They would not necessarily get
* 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];
pull_varattnos((Node *) indexInfo->ii_Expressions, 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,
indexattrs))
* If none matches, build a new index by calling ourselves
* 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];
Relation childrel;
Datum *aggvalues = econtext->ecxt_aggvalues;
bool *aggnulls = econtext->ecxt_aggnulls;
int aggno;
- int transno;
/*
* If there were any DISTINCT and/or ORDER BY aggregates, sort their
* 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];
AggStatePerGroup pergroupstate;
int arrlen;
ListCell *l;
ListCell *cell;
- int i;
int path_index;
int min_index;
int max_index;
for_each_cell(l, subpaths, cell)
{
Path *subpath = (Path *) lfirst(l);
- int i;
/* Consider only the non-partial paths */
if (path_index++ == numpaths)
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;
}
/* 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;
Bitmapset *keys, List *exprs,
MCVList *mcvlist, bool is_or)
{
- int i;
ListCell *l;
bool *matches;
* can skip items that were already ruled out, and terminate if
* 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;
MCVItem *item = &mcvlist->items[i];
* can skip items that were already ruled out, and terminate if
* 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;
bool match = !expr->useOr;
* can skip items that were already ruled out, and terminate if
* 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 */
MCVItem *item = &mcvlist->items[i];
* can skip items that were already ruled out, and terminate if
* 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];
bool match = false;
* can skip items that were already ruled out, and terminate if
* 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;
MCVItem *item = &mcvlist->items[i];
DropRelationsAllBuffers(SMgrRelation *smgr_reln, int nlocators)
{
int i;
- int j;
int n = 0;
SMgrRelation *rels;
BlockNumber (*block)[MAX_FORKNUM + 1];
*/
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. */
block[i][j] = smgrnblocks_cached(rels[i], j);
{
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 */
if (!BlockNumberIsValid(block[i][j]))
char **configitems = NULL;
int nconfigitems = 0;
const char *keyword;
- int i;
/* Do nothing in data-only dump */
if (dopt->dataOnly)
finfo->dobj.name);
}
- for (i = 0; i < nconfigitems; i++)
+ for (int i = 0; i < nconfigitems; i++)
{
/* we feel free to scribble on configitems[] here */
char *configitem = configitems[i];
int weight_tmp;
int rscale_tmp;
int ri;
- int i;
long guess;
long first_have;
long first_div;
* Initialize local variables
*/
init_var(÷nd);
- for (i = 1; i < 10; i++)
+ for (int i = 1; i < 10; i++)
init_var(&divisor[i]);
/*
if (dividend.buf != NULL)
digitbuf_free(dividend.buf);
- for (i = 1; i < 10; i++)
+ for (int i = 1; i < 10; i++)
{
if (divisor[i].buf != NULL)
digitbuf_free(divisor[i].buf);