]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Fix local-variable shadowing in pg_trgm's printSourceNFA().
authorTom Lane <tgl@sss.pgh.pa.us>
Mon, 2 Mar 2026 19:40:29 +0000 (14:40 -0500)
committerTom Lane <tgl@sss.pgh.pa.us>
Mon, 2 Mar 2026 19:40:29 +0000 (14:40 -0500)
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

contrib/pg_trgm/trgm_regexp.c

index efee4cf5fb4bca2a48f4accd425ef86c664ef658..b4eaeec60902b9ac8cf8504e7edae2a236f3752b 100644 (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];