diff --git a/src/regex_impl.hh b/src/regex_impl.hh
index 9d1748bb..57f07c8b 100644
--- a/src/regex_impl.hh
+++ b/src/regex_impl.hh
@@ -504,7 +504,6 @@ private:
if (start_desc and m_threads.next_is_empty())
to_next_start(pos, config, *start_desc);
m_threads.push_next({first_inst, -1});
- m_threads.grow_ifn(false);
}
m_threads.swap_next();
}
@@ -632,7 +631,7 @@ private:
void push_current(Thread thread) { m_data[decrement(m_current)] = thread; grow_ifn(true); }
Thread pop_current() { return m_data[post_increment(m_current)]; }
- void push_next(Thread thread) { m_data[post_increment(m_next_end)] = thread; }
+ void push_next(Thread thread) { m_data[post_increment(m_next_end)] = thread; grow_ifn(false); }
Thread pop_next() { return m_data[decrement(m_next_end)]; }
void swap_next()
diff --git a/test/regression/4859-regex-invalid-behaviour/cmd b/test/regression/4859-regex-invalid-behaviour/cmd
new file mode 100644
index 00000000..170cee79
--- /dev/null
+++ b/test/regression/4859-regex-invalid-behaviour/cmd
@@ -0,0 +1 @@
+ged
diff --git a/test/regression/4859-regex-invalid-behaviour/in b/test/regression/4859-regex-invalid-behaviour/in
new file mode 100644
index 00000000..73573eb5
--- /dev/null
+++ b/test/regression/4859-regex-invalid-behaviour/in
@@ -0,0 +1,3 @@
+ ddddd
+ aaaaa
+ bbbbb
diff --git a/test/regression/4859-regex-invalid-behaviour/out b/test/regression/4859-regex-invalid-behaviour/out
new file mode 100644
index 00000000..df031279
--- /dev/null
+++ b/test/regression/4859-regex-invalid-behaviour/out
@@ -0,0 +1 @@
+ bbbbb
diff --git a/test/regression/4859-regex-invalid-behaviour/rc b/test/regression/4859-regex-invalid-behaviour/rc
new file mode 100644
index 00000000..fabf8e5f
--- /dev/null
+++ b/test/regression/4859-regex-invalid-behaviour/rc
@@ -0,0 +1 @@
+reg slash '(?S)((^ {13}d.*\n)(^ {13}.*\n)*?)?^.'