Skip to content

Commit 91cf313

Browse files
committed
Fix minor bug in regexp makesearch() function.
The list-wrangling here was done wrong, allowing the same state to get put into the list twice. The following loop then would clone it twice. The second clone would wind up with no inarcs, so that there was no observable misbehavior AFAICT, but a useless state in the finished NFA isn't an especially good thing.
1 parent 223936e commit 91cf313

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

src/backend/regex/regcomp.c

+12-7
Original file line numberDiff line numberDiff line change
@@ -568,21 +568,26 @@ makesearch(struct vars * v,
568568
* splitting each such state into progress and no-progress states.
569569
*/
570570

571-
/* first, make a list of the states */
571+
/* first, make a list of the states reachable from pre and elsewhere */
572572
slist = NULL;
573573
for (a = pre->outs; a != NULL; a = a->outchain)
574574
{
575575
s = a->to;
576576
for (b = s->ins; b != NULL; b = b->inchain)
577+
{
577578
if (b->from != pre)
578579
break;
580+
}
581+
582+
/*
583+
* We want to mark states as being in the list already by having non
584+
* NULL tmp fields, but we can't just store the old slist value in tmp
585+
* because that doesn't work for the first such state. Instead, the
586+
* first list entry gets its own address in tmp.
587+
*/
579588
if (b != NULL && s->tmp == NULL)
580589
{
581-
/*
582-
* Must be split if not already in the list (fixes bugs 505048,
583-
* 230589, 840258, 504785).
584-
*/
585-
s->tmp = slist;
590+
s->tmp = (slist != NULL) ? slist : s;
586591
slist = s;
587592
}
588593
}
@@ -601,7 +606,7 @@ makesearch(struct vars * v,
601606
freearc(nfa, a);
602607
}
603608
}
604-
s2 = s->tmp;
609+
s2 = (s->tmp != s) ? s->tmp : NULL;
605610
s->tmp = NULL; /* clean up while we're at it */
606611
}
607612
}

0 commit comments

Comments
 (0)