From 0bee44c9dc9bee64d1143aa0febd2b61819d35bd Mon Sep 17 00:00:00 2001 From: Mike Pall Date: Sat, 21 Dec 2019 13:52:47 +0100 Subject: [PATCH] Properly fix pointer diff in string.find(). Thanks to Vyacheslav Egorov. --- src/lj_ffrecord.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lj_ffrecord.c b/src/lj_ffrecord.c index cb374beb..c673d650 100644 --- a/src/lj_ffrecord.c +++ b/src/lj_ffrecord.c @@ -949,8 +949,8 @@ static void LJ_FASTCALL recff_string_find(jit_State *J, RecordFFData *rd) str->len-(MSize)start, pat->len)) { TRef pos; emitir(IRTG(IR_NE, IRT_PGC), tr, trp0); - /* Don't use STRREF of trstr. We need a pointer diff. */ - pos = emitir(IRTI(IR_SUB), emitir(IRTI(IR_SUB), tr, trstr), lj_ir_kint(J, sizeof(GCstr))); + /* Recompute offset. trsptr may not point into trstr after folding. */ + pos = emitir(IRTI(IR_ADD), emitir(IRTI(IR_SUB), tr, trsptr), trstart); J->base[0] = emitir(IRTI(IR_ADD), pos, lj_ir_kint(J, 1)); J->base[1] = emitir(IRTI(IR_ADD), pos, trplen); rd->nres = 2;