]> granicus.if.org Git - re2c/commitdiff
Fix for possible invalidated iterator after resize
authorRyan Mast <ryan@ahitb.com>
Sun, 2 Jul 2017 19:59:09 +0000 (12:59 -0700)
committerUlya Trofimovich <skvadrik@gmail.com>
Sun, 2 Jul 2017 21:11:32 +0000 (22:11 +0100)
re2c/src/dfa/closure.cc

index 608d67806f7b5d9d78bcbf7a327286b30a66569a..29625bb37ca00bb70f41eabdd055eb412971893d 100644 (file)
@@ -202,7 +202,7 @@ void raw_closure(const closure_t &init, closure_t &done, closure_t *shadow,
        // drop "inner" states (non-final without outgoing non-epsilon transitions)
        j = std::partition(b, e, clos_t::ran);
        e = std::partition(j, e, clos_t::fin);
-       done.resize(static_cast<size_t>(e - b));
+       size_t n = static_cast<size_t>(e - b);
 
        // drop all final states except one; mark dropped rules as shadowed
        // see note [at most one final item per closure]
@@ -212,8 +212,10 @@ void raw_closure(const closure_t &init, closure_t &done, closure_t *shadow,
                for (i = j; ++i < e;) {
                        rules[i->state->rule].shadow.insert(l);
                }
-               done.resize(static_cast<size_t>(j - b) + 1);
+               n = static_cast<size_t>(j - b) + 1;
        }
+
+       done.resize(n);
 }
 
 /* note [at most one final item per closure]