Regex: Ensure we only ever have a single thread on a given instruction

This commit is contained in:
Maxime Coste 2017-09-18 11:30:01 +09:00
parent ee42c6b0ba
commit a9a04e81b0

View File

@ -311,10 +311,13 @@ struct ThreadedExecutor
return { StepResult::Consumed, inst };
case RegexProgram::Jump:
inst = m_program.begin() + *reinterpret_cast<const RegexProgram::Offset*>(inst);
// if instruction is already going to be executed, drop this thread
if (std::find(m_threads.begin(), m_threads.end(), inst) != m_threads.end())
return { StepResult::Failed };
break;
case RegexProgram::Split:
{
m_threads.push_back(m_program.begin() + *reinterpret_cast<const RegexProgram::Offset*>(inst));
add_thread(*reinterpret_cast<const RegexProgram::Offset*>(inst));
inst += sizeof(RegexProgram::Offset);
break;
}
@ -362,6 +365,13 @@ struct ThreadedExecutor
return false;
}
void add_thread(RegexProgram::Offset pos)
{
const char* inst = m_program.begin() + pos;
if (std::find(m_threads.begin(), m_threads.end(), inst) == m_threads.end())
m_threads.push_back(inst);
}
bool is_line_start() const
{
return m_pos == m_subject.begin() or *(m_pos-1) == '\n';