Bug: Workq::mark() sets last_was_mark_ to false instead of true
- Dominant language
- C++
- Stars
- 9.8k
- Forks
- 1.2k
- PR merge metrics
- No merged PRs in 30d
Description
In `re2/dfa.cc`, the `Workq::mark()` method sets `last_was_mark_` to `false` on line 391. It should set it to `true`. The purpose of this flag is to prevent consecutive duplicate marks from being inserted into the work queue. Because the flag is never set to `true`, a second call to `mark()` without an intervening `insert()` will not be deduplicated.
## Code
```cpp
// re2/dfa.cc:388-393
void mark() {
if (last_was_mark_)
return;
last_was_mark_ = false; // BUG: should be true
SparseSet::insert_new(nextmark_++);
}
```
## Impact
This is a correctness bug. It affects the longest-match mode where marks are used to track match priority ordering. Duplicate marks waste mark slots and can cause the DFA to produce subtly different results than the NFA for certain patterns.
There is no memory safety issue. The `SparseSet` bounds check in `InsertInternal` (sparse_set.h:147) is active in release builds and prevents out-of-bounds access even if marks overflow.
## Fix
Change line 391 from `last_was_mark_ = false;` to `last_was_mark_ = true;`
I can submit a PR to fix :)
Contributor guide
Assessment
This issue has not been assessed yet.