소스 검색

Properly fix pointer diff in string.find().

Thanks to Vyacheslav Egorov.
Mike Pall 5 년 전
부모
커밋
0bee44c9dc
1개의 변경된 파일2개의 추가작업 그리고 2개의 파일을 삭제
  1. 2 2
      src/lj_ffrecord.c

+ 2 - 2
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;