From aa6025012b01c5e2dee47469a69dbffe464d789c Mon Sep 17 00:00:00 2001 From: Alex Coyte Date: Wed, 19 Jul 2017 10:02:55 +1000 Subject: [PATCH] Ensure max width of repeat before transforming graph. --- src/nfagraph/ng_repeat.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/nfagraph/ng_repeat.cpp b/src/nfagraph/ng_repeat.cpp index 7add6557..96c553de 100644 --- a/src/nfagraph/ng_repeat.cpp +++ b/src/nfagraph/ng_repeat.cpp @@ -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 *repeats, - unordered_map &depths, - unordered_set &created) { + vector *repeats, + unordered_map &depths, + unordered_set &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");