Skip to content

Commit c580431

Browse files
authored
Fix my JIT bug
1 parent 1621949 commit c580431

File tree

3 files changed

+13
-14
lines changed

3 files changed

+13
-14
lines changed

src/pcre2_jit_compile.c

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13783,15 +13783,8 @@ if (common->has_set_som &&
1378313783
struct sljit_jump *bad_som_ahead;
1378413784
struct sljit_jump *fallthrough;
1378513785

13786-
// XXX I want to emit code equivalent to the following:
13787-
// if (OVECTOR(0) < jit_arguments->str || // I believe jit_arguments->str is the start_offset of the match?
13788-
// OVECTOR(0) > OVECTOR(1)))
13789-
// {
13790-
// return PCRE2_ERROR_BAD_BACKSLASH_K;
13791-
// }
13792-
1379313786
OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), OVECTOR(0));
13794-
OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_SP), OVECTOR(1));
13787+
OP1(SLJIT_MOV, TMP2, 0, STR_PTR, 0); /* STR_PTR, since OVECTOR(1) hasn't been populated yet */
1379513788
if (HAS_VIRTUAL_REGISTERS)
1379613789
{
1379713790
OP1(SLJIT_MOV, TMP3, 0, ARGUMENTS, 0);
@@ -13802,14 +13795,10 @@ if (common->has_set_som &&
1380213795
OP1(SLJIT_MOV, TMP3, 0, SLJIT_MEM1(ARGUMENTS), SLJIT_OFFSETOF(jit_arguments, str));
1380313796
}
1380413797

13805-
// Compare if OVECTOR(0) < jit_arguments->str
13806-
bad_som_behind = CMP(SLJIT_LESS, TMP1, 0, TMP3, 0);
13807-
// Compare if OVECTOR(0) > OVECTOR(1)
13808-
bad_som_ahead = CMP(SLJIT_GREATER, TMP1, 0, TMP2, 0);
13809-
13798+
bad_som_behind = CMP(SLJIT_LESS, TMP1, 0, TMP3, 0); /* (ovector[0] < jit_arguments->str)? */
13799+
bad_som_ahead = CMP(SLJIT_GREATER, TMP1, 0, TMP2, 0); /* (ovector[0] > ovector[1])? */
1381013800
fallthrough = JUMP(SLJIT_JUMP);
1381113801

13812-
// If either comparison is true, return error and jump to abort
1381313802
JUMPHERE(bad_som_behind);
1381413803
JUMPHERE(bad_som_ahead);
1381513804
OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE2_ERROR_BAD_BACKSLASH_K);

testdata/testinput2

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6398,6 +6398,10 @@ a)"xI
63986398
ab
63996399
zz
64006400

6401+
/a|(?(DEFINE)(?<sneaky>\K\Ga))(?<=(?&sneaky))b/g
6402+
ab
6403+
zz
6404+
64016405
/(?=.{10}(?1))x(\K){0}/
64026406
x1234567890
64036407

testdata/testoutput2

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19091,6 +19091,12 @@ Failed: error -75: disallowed use of \K in lookaround
1909119091
zz
1909219092
No match
1909319093

19094+
/a|(?(DEFINE)(?<sneaky>\K\Ga))(?<=(?&sneaky))b/g
19095+
ab
19096+
0: a
19097+
zz
19098+
No match
19099+
1909419100
/(?=.{10}(?1))x(\K){0}/
1909519101
x1234567890
1909619102
Failed: error -75: disallowed use of \K in lookaround

0 commit comments

Comments
 (0)