]> git.ipfire.org Git - thirdparty/vectorscan.git/commitdiff
clear_deeper_reports: clear dfa if dead
authorJustin Viiret <justin.viiret@intel.com>
Thu, 22 Jun 2017 06:51:35 +0000 (16:51 +1000)
committerMatthew Barr <matthew.barr@intel.com>
Mon, 21 Aug 2017 01:10:11 +0000 (11:10 +1000)
If we remove all the reports from the DFA because they're too deep, then
clear the DFA without depending on Hopcroft minimisation.

src/nfa/mcclellancompile_util.cpp

index 17e022fe6cc5166b9607bafd12b3e565c50d9c65..8bb258d381406a3ed0c228476b89204b67ef8d5f 100644 (file)
@@ -187,7 +187,22 @@ bool clear_deeper_reports(raw_dfa &raw, u32 max_offset) {
         }
     }
 
-    return changed;
+    if (!changed) {
+        return false;
+    }
+
+    // We may have cleared all reports from the DFA, in which case it should
+    // become empty.
+    if (all_of_in(raw.states, [](const dstate &ds) {
+            return ds.reports.empty() && ds.reports_eod.empty();
+        })) {
+        DEBUG_PRINTF("no reports left at all, dfa is dead\n");
+        raw.states.clear();
+        raw.start_anchored = DEAD_STATE;
+        raw.start_floating = DEAD_STATE;
+    }
+
+    return true;
 }
 
 set<ReportID> all_reports(const raw_dfa &rdfa) {