]> git.ipfire.org Git - thirdparty/vectorscan.git/commitdiff
Ensure max width of repeat before transforming graph.
authorAlex Coyte <a.coyte@intel.com>
Wed, 19 Jul 2017 00:02:55 +0000 (10:02 +1000)
committerMatthew Barr <matthew.barr@intel.com>
Mon, 21 Aug 2017 01:18:30 +0000 (11:18 +1000)
src/nfagraph/ng_repeat.cpp

index 7add6557733fb2dfe8fa261042b7e2cdf271364b..96c553dedfd452c2b6a6face712ac0de1f06d5d5 100644 (file)
@@ -762,13 +762,20 @@ void getSuccessors(const NGHolder &g, const ReachSubgraph &rsi,
  * NFA graph and replace it with a cyclic state. */
 static
 void replaceSubgraphWithSpecial(NGHolder &g, ReachSubgraph &rsi,
-                                vector<BoundedRepeatData> *repeats,
-                                unordered_map<NFAVertex, NFAVertexDepth> &depths,
-                                unordered_set<NFAVertex> &created) {
+                               vector<BoundedRepeatData> *repeats,
+                               unordered_map<NFAVertex, NFAVertexDepth> &depths,
+                               unordered_set<NFAVertex> &created) {
     assert(!rsi.bad);
+    /* As we may need to unpeel 2 vertices, we need the width to be more than 2.
+     * This should only happen if the graph did not have redundancy pass
+     * performed on as vertex count checks would be prevent us reaching here.
+     */
+    if (rsi.repeatMax <= depth(2)) {
+        return;
+    }
     assert(rsi.repeatMin > depth(0));
     assert(rsi.repeatMax >= rsi.repeatMin);
-    assert(rsi.repeatMax > depth(2)); /* may need to unpeel 2 vertices */
+    assert(rsi.repeatMax > depth(2));
 
     DEBUG_PRINTF("entry\n");