]> git.ipfire.org Git - thirdparty/LuaJIT.git/commitdiff
Fix anchoring for string buffer set() method (again).
authorMike Pall <mike>
Sun, 10 Dec 2023 18:42:22 +0000 (19:42 +0100)
committerMike Pall <mike>
Sun, 10 Dec 2023 18:42:22 +0000 (19:42 +0100)
Thanks to Peter Cawley. #1125

src/lj_ffrecord.c

index c70793a44927453d55befa7630298836568431f7..30dc6bfc66da6ca39410e449f8cb3dd244eec451 100644 (file)
@@ -1205,14 +1205,11 @@ static void LJ_FASTCALL recff_buffer_method_set(jit_State *J, RecordFFData *rd)
     TRef trp = emitir(IRT(IR_STRREF, IRT_PGC), tr, lj_ir_kint(J, 0));
     TRef len = emitir(IRTI(IR_FLOAD), tr, IRFL_STR_LEN);
     IRIns *irp = IR(tref_ref(trp));
-    /* Anchor (potentially different) obj into which trp points after fold. */
-    if (irp->o == IR_STRREF) {
+    /* trp must point into the anchored obj, even after folding. */
+    if (irp->o == IR_STRREF)
       tr = irp->op1;
-    } else if (irp->o == IR_KKPTR && !tref_isk(tr)) {
-      GCstr *str = strV(&rd->argv[1]);  /* Constify the argument. */
-      tr = lj_ir_kstr(J, str);
-      trp = lj_ir_kkptr(J, (char *)strdata(str));
-    }
+    else if (!tref_isk(tr))
+      trp = emitir(IRT(IR_ADD, IRT_PGC), tr, lj_ir_kintpgc(J, sizeof(GCstr)));
     lj_ir_call(J, IRCALL_lj_bufx_set, trbuf, trp, len, tr);
 #if LJ_HASFFI
   } else if (tref_iscdata(tr)) {