diff options
author | Mike Pall <mike> | 2024-07-03 23:46:47 +0200 |
---|---|---|
committer | Mike Pall <mike> | 2024-07-03 23:46:47 +0200 |
commit | 7a608e4425ce0777f5c980dad9f4fdc1bcce0b8c (patch) | |
tree | 36b543a13a244f30a48f91d42b509822dd2aea36 | |
parent | f602f0154b644211283cfeea92a570ca38f71947 (diff) | |
download | luajit-7a608e4425ce0777f5c980dad9f4fdc1bcce0b8c.tar.gz luajit-7a608e4425ce0777f5c980dad9f4fdc1bcce0b8c.tar.bz2 luajit-7a608e4425ce0777f5c980dad9f4fdc1bcce0b8c.zip |
FFI: Fix various issues in recff_cdata_arith.
Thanks to Sergey Kaplun. #1224
-rw-r--r-- | src/lj_crecord.c | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/src/lj_crecord.c b/src/lj_crecord.c index 63a72aa4..1f6396f6 100644 --- a/src/lj_crecord.c +++ b/src/lj_crecord.c | |||
@@ -1367,7 +1367,8 @@ static TRef crec_arith_meta(jit_State *J, TRef *sp, CType **s, CTState *cts, | |||
1367 | 1367 | ||
1368 | void LJ_FASTCALL recff_cdata_arith(jit_State *J, RecordFFData *rd) | 1368 | void LJ_FASTCALL recff_cdata_arith(jit_State *J, RecordFFData *rd) |
1369 | { | 1369 | { |
1370 | CTState *cts = ctype_ctsG(J2G(J)); | 1370 | CTState *cts = ctype_cts(J->L); |
1371 | MMS mm = (MMS)rd->data; | ||
1371 | TRef sp[2]; | 1372 | TRef sp[2]; |
1372 | CType *s[2]; | 1373 | CType *s[2]; |
1373 | MSize i; | 1374 | MSize i; |
@@ -1417,6 +1418,8 @@ void LJ_FASTCALL recff_cdata_arith(jit_State *J, RecordFFData *rd) | |||
1417 | } | 1418 | } |
1418 | } | 1419 | } |
1419 | } else if (tref_isnil(tr)) { | 1420 | } else if (tref_isnil(tr)) { |
1421 | if (!(mm == MM_len || mm == MM_eq || mm == MM_lt || mm == MM_le)) | ||
1422 | lj_trace_err(J, LJ_TRERR_BADTYPE); | ||
1420 | tr = lj_ir_kptr(J, NULL); | 1423 | tr = lj_ir_kptr(J, NULL); |
1421 | ct = ctype_get(cts, CTID_P_VOID); | 1424 | ct = ctype_get(cts, CTID_P_VOID); |
1422 | } else if (tref_isinteger(tr)) { | 1425 | } else if (tref_isinteger(tr)) { |
@@ -1435,12 +1438,12 @@ void LJ_FASTCALL recff_cdata_arith(jit_State *J, RecordFFData *rd) | |||
1435 | ct = ctype_child(cts, cct); | 1438 | ct = ctype_child(cts, cct); |
1436 | tr = lj_ir_kint(J, (int32_t)ofs); | 1439 | tr = lj_ir_kint(J, (int32_t)ofs); |
1437 | } else { /* Interpreter will throw or return false. */ | 1440 | } else { /* Interpreter will throw or return false. */ |
1438 | ct = ctype_get(cts, CTID_P_VOID); | 1441 | lj_trace_err(J, LJ_TRERR_BADTYPE); |
1439 | } | 1442 | } |
1440 | } else if (ctype_isptr(ct->info)) { | 1443 | } else if (ctype_isptr(ct->info)) { |
1441 | tr = emitir(IRT(IR_ADD, IRT_PTR), tr, lj_ir_kintp(J, sizeof(GCstr))); | 1444 | tr = emitir(IRT(IR_ADD, IRT_PTR), tr, lj_ir_kintp(J, sizeof(GCstr))); |
1442 | } else { | 1445 | } else { |
1443 | ct = ctype_get(cts, CTID_P_VOID); | 1446 | lj_trace_err(J, LJ_TRERR_BADTYPE); |
1444 | } | 1447 | } |
1445 | } else if (!tref_isnum(tr)) { | 1448 | } else if (!tref_isnum(tr)) { |
1446 | tr = 0; | 1449 | tr = 0; |
@@ -1452,7 +1455,6 @@ void LJ_FASTCALL recff_cdata_arith(jit_State *J, RecordFFData *rd) | |||
1452 | } | 1455 | } |
1453 | { | 1456 | { |
1454 | TRef tr; | 1457 | TRef tr; |
1455 | MMS mm = (MMS)rd->data; | ||
1456 | if ((mm == MM_len || mm == MM_concat || | 1458 | if ((mm == MM_len || mm == MM_concat || |
1457 | (!(tr = crec_arith_int64(J, sp, s, mm)) && | 1459 | (!(tr = crec_arith_int64(J, sp, s, mm)) && |
1458 | !(tr = crec_arith_ptr(J, sp, s, mm)))) && | 1460 | !(tr = crec_arith_ptr(J, sp, s, mm)))) && |