From: Tom Lane Date: Mon, 2 Mar 2026 19:40:29 +0000 (-0500) Subject: Fix local-variable shadowing in pg_trgm's printSourceNFA(). X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cdaa67565867ba443afb66b9e82023d65487dc7c;p=thirdparty%2Fpostgresql.git 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 Author: Tom Lane Discussion: https://postgr.es/m/3009911772478436@08341ecb-668d-43a9-af4d-b45f00c72521 --- diff --git a/contrib/pg_trgm/trgm_regexp.c b/contrib/pg_trgm/trgm_regexp.c index efee4cf5fb4..b4eaeec6090 100644 --- a/contrib/pg_trgm/trgm_regexp.c +++ b/contrib/pg_trgm/trgm_regexp.c @@ -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, "
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];