Fix local-variable shadowing in pg_trgm's printSourceNFA().

We hadn't noticed this violation of -Wshadow=compatible-local
because this function isn't compiled without -DTRGM_REGEXP_DEBUG.

As long as we have to clean it up, let's do so by converting all
this function's loops to use C99 loop-local control variables.

Reported-by: Sergei Kornilov <sk@zsrv.org>
Author: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/3009911772478436@08341ecb-668d-43a9-af4d-b45f00c72521
This commit is contained in:
Tom Lane 2026-03-02 14:40:29 -05:00
parent f191dc6766
commit cdaa675658

View file

@ -2129,18 +2129,15 @@ printSourceNFA(regex_t *regex, TrgmColorInfo *colors, int ncolors)
{
StringInfoData buf;
int nstates = pg_reg_getnumstates(regex);
int state;
int i;
initStringInfo(&buf);
appendStringInfoString(&buf, "\ndigraph sourceNFA {\n");
for (state = 0; state < nstates; state++)
for (int state = 0; state < nstates; state++)
{
regex_arc_t *arcs;
int i,
arcsCount;
int arcsCount;
appendStringInfo(&buf, "s%d", state);
if (pg_reg_getfinalstate(regex) == state)
@ -2151,7 +2148,7 @@ printSourceNFA(regex_t *regex, TrgmColorInfo *colors, int ncolors)
arcs = palloc_array(regex_arc_t, arcsCount);
pg_reg_getoutarcs(regex, state, arcs, arcsCount);
for (i = 0; i < arcsCount; i++)
for (int i = 0; i < arcsCount; i++)
{
appendStringInfo(&buf, " s%d -> s%d [label = \"%d\"];\n",
state, arcs[i].to, arcs[i].co);
@ -2168,15 +2165,14 @@ printSourceNFA(regex_t *regex, TrgmColorInfo *colors, int ncolors)
appendStringInfoString(&buf, " { rank = sink;\n");
appendStringInfoString(&buf, " Colors [shape = none, margin=0, label=<\n");
for (i = 0; i < ncolors; i++)
for (int i = 0; i < ncolors; i++)
{
TrgmColorInfo *color = &colors[i];
int j;
appendStringInfo(&buf, "<br/>Color %d: ", i);
if (color->expandable)
{
for (j = 0; j < color->wordCharsCount; j++)
for (int j = 0; j < color->wordCharsCount; j++)
{
char s[MAX_MULTIBYTE_CHAR_LEN + 1];