Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit f01592f

Browse files
committed
Remove shadowed local variables that are new in v15
Compiling with -Wshadow=compatible-local yields quite a few warnings about local variables being shadowed by compatible local variables in an inner scope. Of course, this is perfectly valid in C, but we have had bugs in the past as a result of developers failing to notice this. af7d270 is a recent example. Here we do a cleanup of warnings we receive from -Wshadow=compatible-local for code which is new to PostgreSQL 15. We've yet to have the discussion about if we actually ever want to run that as a standard compilation flag. We'll need to at least get the number of warnings down to something easier to manage before we can realistically consider if we want this or not. This commit is the first step towards reducing the warnings. The changes being made here are all fairly trivial. Because of that, and the fact that v15 is still in beta, this is being back-patched into 15. It seems more risky not to do this as the risk of future bugs is increased by the additional conflicts that this commit could cause for any future bug fixes touching the same areas as this commit. Author: Justin Pryzby Discussion: https://postgr.es/m/20220817145434.GC26426%40telsasoft.com Backpatch-through: 15
1 parent 3097bde commit f01592f

File tree

5 files changed

+39
-46
lines changed

5 files changed

+39
-46
lines changed

src/backend/backup/basebackup_target.c

+6-6
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ BaseBackupAddTarget(char *name,
6262
void *(*check_detail) (char *, char *),
6363
bbsink *(*get_sink) (bbsink *, void *))
6464
{
65-
BaseBackupTargetType *ttype;
65+
BaseBackupTargetType *newtype;
6666
MemoryContext oldcontext;
6767
ListCell *lc;
6868

@@ -96,11 +96,11 @@ BaseBackupAddTarget(char *name,
9696
* name into a newly-allocated chunk of memory.
9797
*/
9898
oldcontext = MemoryContextSwitchTo(TopMemoryContext);
99-
ttype = palloc(sizeof(BaseBackupTargetType));
100-
ttype->name = pstrdup(name);
101-
ttype->check_detail = check_detail;
102-
ttype->get_sink = get_sink;
103-
BaseBackupTargetTypeList = lappend(BaseBackupTargetTypeList, ttype);
99+
newtype = palloc(sizeof(BaseBackupTargetType));
100+
newtype->name = pstrdup(name);
101+
newtype->check_detail = check_detail;
102+
newtype->get_sink = get_sink;
103+
BaseBackupTargetTypeList = lappend(BaseBackupTargetTypeList, newtype);
104104
MemoryContextSwitchTo(oldcontext);
105105
}
106106

src/backend/parser/parse_jsontable.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -341,13 +341,13 @@ transformJsonTableChildPlan(JsonTableContext *cxt, JsonTablePlan *plan,
341341
/* transform all nested columns into cross/union join */
342342
foreach(lc, columns)
343343
{
344-
JsonTableColumn *jtc = castNode(JsonTableColumn, lfirst(lc));
344+
JsonTableColumn *col = castNode(JsonTableColumn, lfirst(lc));
345345
Node *node;
346346

347-
if (jtc->coltype != JTC_NESTED)
347+
if (col->coltype != JTC_NESTED)
348348
continue;
349349

350-
node = transformNestedJsonTableColumn(cxt, jtc, plan);
350+
node = transformNestedJsonTableColumn(cxt, col, plan);
351351

352352
/* join transformed node with previous sibling nodes */
353353
res = res ? makeJsonTableSiblingJoin(cross, res, node) : node;

src/backend/replication/logical/tablesync.c

+8-15
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,6 @@ fetch_remote_table_info(char *nspname, char *relname,
707707
bool isnull;
708708
int natt;
709709
ListCell *lc;
710-
bool first;
711710
Bitmapset *included_cols = NULL;
712711

713712
lrel->nspname = nspname;
@@ -759,18 +758,15 @@ fetch_remote_table_info(char *nspname, char *relname,
759758
if (walrcv_server_version(LogRepWorkerWalRcvConn) >= 150000)
760759
{
761760
WalRcvExecResult *pubres;
762-
TupleTableSlot *slot;
761+
TupleTableSlot *tslot;
763762
Oid attrsRow[] = {INT2VECTOROID};
764763
StringInfoData pub_names;
765-
bool first = true;
766-
767764
initStringInfo(&pub_names);
768765
foreach(lc, MySubscription->publications)
769766
{
770-
if (!first)
767+
if (foreach_current_index(lc) > 0)
771768
appendStringInfo(&pub_names, ", ");
772769
appendStringInfoString(&pub_names, quote_literal_cstr(strVal(lfirst(lc))));
773-
first = false;
774770
}
775771

776772
/*
@@ -819,10 +815,10 @@ fetch_remote_table_info(char *nspname, char *relname,
819815
* If we find a NULL value, it means all the columns should be
820816
* replicated.
821817
*/
822-
slot = MakeSingleTupleTableSlot(pubres->tupledesc, &TTSOpsMinimalTuple);
823-
if (tuplestore_gettupleslot(pubres->tuplestore, true, false, slot))
818+
tslot = MakeSingleTupleTableSlot(pubres->tupledesc, &TTSOpsMinimalTuple);
819+
if (tuplestore_gettupleslot(pubres->tuplestore, true, false, tslot))
824820
{
825-
Datum cfval = slot_getattr(slot, 1, &isnull);
821+
Datum cfval = slot_getattr(tslot, 1, &isnull);
826822

827823
if (!isnull)
828824
{
@@ -838,9 +834,9 @@ fetch_remote_table_info(char *nspname, char *relname,
838834
included_cols = bms_add_member(included_cols, elems[natt]);
839835
}
840836

841-
ExecClearTuple(slot);
837+
ExecClearTuple(tslot);
842838
}
843-
ExecDropSingleTupleTableSlot(slot);
839+
ExecDropSingleTupleTableSlot(tslot);
844840

845841
walrcv_clear_result(pubres);
846842

@@ -950,14 +946,11 @@ fetch_remote_table_info(char *nspname, char *relname,
950946

951947
/* Build the pubname list. */
952948
initStringInfo(&pub_names);
953-
first = true;
954949
foreach(lc, MySubscription->publications)
955950
{
956951
char *pubname = strVal(lfirst(lc));
957952

958-
if (first)
959-
first = false;
960-
else
953+
if (foreach_current_index(lc) > 0)
961954
appendStringInfoString(&pub_names, ", ");
962955

963956
appendStringInfoString(&pub_names, quote_literal_cstr(pubname));

src/backend/utils/adt/jsonpath_exec.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -3109,10 +3109,10 @@ JsonItemFromDatum(Datum val, Oid typid, int32 typmod, JsonbValue *res)
31093109

31103110
if (JsonContainerIsScalar(&jb->root))
31113111
{
3112-
bool res PG_USED_FOR_ASSERTS_ONLY;
3112+
bool result PG_USED_FOR_ASSERTS_ONLY;
31133113

3114-
res = JsonbExtractScalar(&jb->root, jbv);
3115-
Assert(res);
3114+
result = JsonbExtractScalar(&jb->root, jbv);
3115+
Assert(result);
31163116
}
31173117
else
31183118
JsonbInitBinary(jbv, jb);

src/bin/pg_dump/pg_dump.c

+19-19
Original file line numberDiff line numberDiff line change
@@ -3142,10 +3142,10 @@ dumpDatabase(Archive *fout)
31423142
PQExpBuffer loFrozenQry = createPQExpBuffer();
31433143
PQExpBuffer loOutQry = createPQExpBuffer();
31443144
PQExpBuffer loHorizonQry = createPQExpBuffer();
3145-
int i_relfrozenxid,
3146-
i_relfilenode,
3147-
i_oid,
3148-
i_relminmxid;
3145+
int ii_relfrozenxid,
3146+
ii_relfilenode,
3147+
ii_oid,
3148+
ii_relminmxid;
31493149

31503150
/*
31513151
* pg_largeobject
@@ -3163,10 +3163,10 @@ dumpDatabase(Archive *fout)
31633163

31643164
lo_res = ExecuteSqlQuery(fout, loFrozenQry->data, PGRES_TUPLES_OK);
31653165

3166-
i_relfrozenxid = PQfnumber(lo_res, "relfrozenxid");
3167-
i_relminmxid = PQfnumber(lo_res, "relminmxid");
3168-
i_relfilenode = PQfnumber(lo_res, "relfilenode");
3169-
i_oid = PQfnumber(lo_res, "oid");
3166+
ii_relfrozenxid = PQfnumber(lo_res, "relfrozenxid");
3167+
ii_relminmxid = PQfnumber(lo_res, "relminmxid");
3168+
ii_relfilenode = PQfnumber(lo_res, "relfilenode");
3169+
ii_oid = PQfnumber(lo_res, "oid");
31703170

31713171
appendPQExpBufferStr(loHorizonQry, "\n-- For binary upgrade, set pg_largeobject relfrozenxid and relminmxid\n");
31723172
appendPQExpBufferStr(loOutQry, "\n-- For binary upgrade, preserve pg_largeobject and index relfilenodes\n");
@@ -3178,12 +3178,12 @@ dumpDatabase(Archive *fout)
31783178
appendPQExpBuffer(loHorizonQry, "UPDATE pg_catalog.pg_class\n"
31793179
"SET relfrozenxid = '%u', relminmxid = '%u'\n"
31803180
"WHERE oid = %u;\n",
3181-
atooid(PQgetvalue(lo_res, i, i_relfrozenxid)),
3182-
atooid(PQgetvalue(lo_res, i, i_relminmxid)),
3183-
atooid(PQgetvalue(lo_res, i, i_oid)));
3181+
atooid(PQgetvalue(lo_res, i, ii_relfrozenxid)),
3182+
atooid(PQgetvalue(lo_res, i, ii_relminmxid)),
3183+
atooid(PQgetvalue(lo_res, i, ii_oid)));
31843184

3185-
oid = atooid(PQgetvalue(lo_res, i, i_oid));
3186-
relfilenumber = atooid(PQgetvalue(lo_res, i, i_relfilenode));
3185+
oid = atooid(PQgetvalue(lo_res, i, ii_oid));
3186+
relfilenumber = atooid(PQgetvalue(lo_res, i, ii_relfilenode));
31873187

31883188
if (oid == LargeObjectRelationId)
31893189
appendPQExpBuffer(loOutQry,
@@ -7081,21 +7081,21 @@ getConstraints(Archive *fout, TableInfo tblinfo[], int numTables)
70817081
appendPQExpBufferChar(tbloids, '{');
70827082
for (int i = 0; i < numTables; i++)
70837083
{
7084-
TableInfo *tbinfo = &tblinfo[i];
7084+
TableInfo *tinfo = &tblinfo[i];
70857085

70867086
/*
70877087
* For partitioned tables, foreign keys have no triggers so they must
70887088
* be included anyway in case some foreign keys are defined.
70897089
*/
7090-
if ((!tbinfo->hastriggers &&
7091-
tbinfo->relkind != RELKIND_PARTITIONED_TABLE) ||
7092-
!(tbinfo->dobj.dump & DUMP_COMPONENT_DEFINITION))
7090+
if ((!tinfo->hastriggers &&
7091+
tinfo->relkind != RELKIND_PARTITIONED_TABLE) ||
7092+
!(tinfo->dobj.dump & DUMP_COMPONENT_DEFINITION))
70937093
continue;
70947094

70957095
/* OK, we need info for this table */
70967096
if (tbloids->len > 1) /* do we have more than the '{'? */
70977097
appendPQExpBufferChar(tbloids, ',');
7098-
appendPQExpBuffer(tbloids, "%u", tbinfo->dobj.catId.oid);
7098+
appendPQExpBuffer(tbloids, "%u", tinfo->dobj.catId.oid);
70997099
}
71007100
appendPQExpBufferChar(tbloids, '}');
71017101

@@ -16800,7 +16800,7 @@ dumpSequence(Archive *fout, const TableInfo *tbinfo)
1680016800
*/
1680116801
if (OidIsValid(tbinfo->owning_tab) && !tbinfo->is_identity_sequence)
1680216802
{
16803-
TableInfo *owning_tab = findTableByOid(tbinfo->owning_tab);
16803+
owning_tab = findTableByOid(tbinfo->owning_tab);
1680416804

1680516805
if (owning_tab == NULL)
1680616806
pg_fatal("failed sanity check, parent table with OID %u of sequence with OID %u not found",

0 commit comments

Comments
 (0)