Commit 688dda36
688dda3686a6Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 1 file · ~1 modified
Description
fix(regexp): insert_inst patches lookahead/lookbehind offsets (#824)
When insert_inst grew the bytecode buffer at position pos, it fixed JMP/SPLIT/SPLITNG offsets pointing past pos -- but skipped the four lookahead/lookbehind opcodes (RE_LOOKAHEAD, RE_NEG_LOOKAHEAD, RE_LOOKBEHIND, RE_NEG_LOOKBEHIND), whose offset is also a jump-to-end target.
A pattern like (?=a)b that triggered an insert (e.g. via a
later quantifier) would have its lookahead offset point one
instruction short, producing wrong match positions.
Extend the patch loop to cover all four lookaround opcodes.
Closes #824
Co-Authored-By: Claude Opus 4.7 [email protected]
Details
- Commit
- 688dda3686a6
- Parent
- 0b3b357ec2c0
lib/regexp/re_compile.cmodifiedView file
@@ -90,11 +90,16 @@
9090
c->code[pos].a = a;9191
c->code[pos].offset = offset;9292
93-
/* fix all jump targets that point at or past the insertion point */93+
/* fix all jump targets that point at or past the insertion point.94+
Issue #824: previously only JMP/SPLIT/SPLITNG offsets were95+
patched, leaving LOOKAHEAD/NEG_LOOKAHEAD/LOOKBEHIND/NEG_LOOKBEHIND96+
dangling (their offset is the jump-to-end target). */9497
for (uint32_t i = 0; i < c->code_len; i++) {9598
if (i == pos) continue;9699
switch (c->code[i].op) {97100
case RE_JMP: case RE_SPLIT: case RE_SPLITNG:101+
case RE_LOOKAHEAD: case RE_NEG_LOOKAHEAD:102+
case RE_LOOKBEHIND: case RE_NEG_LOOKBEHIND:98103
if (c->code[i].offset >= pos && c->code[i].offset < 0xffff) {99104
c->code[i].offset++;100105
}