Suppress compiler warning in new regex match-all detection code.
authorTom Lane <tgl@sss.pgh.pa.us>
Tue, 23 Feb 2021 18:55:11 +0000 (13:55 -0500)
committerTom Lane <tgl@sss.pgh.pa.us>
Tue, 23 Feb 2021 18:55:34 +0000 (13:55 -0500)
gcc 10 is smart enough to notice that control could reach this
"hasmatch[depth]" assignment with depth < 0, but not smart enough
to know that that would require a badly broken NFA graph.  Change
the assert() to a plain runtime test to shut it up.

Per report from Andres Freund.

Discussion: https://postgr.es/m/20210223173437.b3ywijygsy6q42gq@alap3.anarazel.de

src/backend/regex/regc_nfa.c

index 1a6c9ce183816f978d3d305f617a1b83a838a847..69929eddfcc6042a4b3ffd4ba7ac5755c68d6e44 100644 (file)
@@ -3082,8 +3082,13 @@ checkmatchall_recurse(struct nfa *nfa, struct state *s,
                {
                        /* We found an all-RAINBOW path to the post state */
                        result = true;
+                       /* ... which should not be adjacent to the pre state */
+                       if (depth < 0)
+                       {
+                               NERR(REG_ASSERT);
+                               return false;
+                       }
                        /* Record potential match lengths */
-                       assert(depth >= 0);
                        hasmatch[depth] = true;
                        if (foundloop)
                        {