LibRegex: Use the right offset when patching jumps through fork-trees

Fixes #4474.
This commit is contained in:
Ali Mohammad Pur 2025-04-25 20:43:33 +02:00 committed by Ali Mohammad Pur
commit 022cd1adca
Notes: github-actions[bot] 2025-04-27 10:17:08 +00:00
2 changed files with 3 additions and 1 deletions

View file

@ -1560,7 +1560,7 @@ void Optimizer::append_alternation(ByteCode& target, Span<ByteCode> alternatives
target.append(static_cast<ByteCodeValueType>(OpCodeId::ForkJump));
patch_location = target.size();
should_negate = false;
patch_size = 2;
patch_size = 1;
target.append(static_cast<ByteCodeValueType>(0));
}

View file

@ -1137,6 +1137,8 @@ TEST_CASE(optimizer_alternation)
Tuple { "(xxxxxxxxxxxxxxxxxxxxxxx|xxxxxxxxxxxxxxxxxxxxxxx)?b"sv, "xxxxxxxxxxxxxxxxxxxxxxx"sv, 0u },
// Don't take the jump in JumpNonEmpty with nonexistent checkpoints (also don't crash).
Tuple { "(?!\\d*|[g-ta-r]+|[h-l]|\\S|\\S|\\S){,9}|\\S{7,8}|\\d|(?<wnvdfimiwd>)|[c-mj-tb-o]*|\\s"sv, "rjvogg7pm|li4nmct mjb2|pk7s8e0"sv, 0u },
// Use the right offset when patching jumps through a fork-tree
Tuple { "(?!a)|(?!a)b"sv, "b"sv, 0u },
};
for (auto& test : tests) {