From 4ed3ee1f046618c5251baae3013f125b4cc7ca9c Mon Sep 17 00:00:00 2001 From: Mike Pall Date: Tue, 8 Apr 2014 12:10:51 +0200 Subject: [PATCH] FFI: Fix cdata equality comparison against strings. --- src/lj_carith.c | 4 ++-- src/lj_crecord.c | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/lj_carith.c b/src/lj_carith.c index 92fe5597..36d7abb1 100644 --- a/src/lj_carith.c +++ b/src/lj_carith.c @@ -62,7 +62,7 @@ static int carith_checkarg(lua_State *L, CTState *cts, CDArith *ca) TValue *o2 = i == 0 ? o+1 : o-1; CType *ct = ctype_raw(cts, cdataV(o2)->ctypeid); ca->ct[i] = NULL; - ca->p[i] = NULL; + ca->p[i] = (uint8_t *)strVdata(o); ok = 0; if (ctype_isenum(ct->info)) { CTSize ofs; @@ -73,7 +73,7 @@ static int carith_checkarg(lua_State *L, CTState *cts, CDArith *ca) ok = 1; } else { ca->ct[1-i] = ct; /* Use enum to improve error message. */ - ca->p[1-i] = (void *)(intptr_t)1; /* To make it unequal. */ + ca->p[1-i] = NULL; break; } } diff --git a/src/lj_crecord.c b/src/lj_crecord.c index 71f3d069..8612f005 100644 --- a/src/lj_crecord.c +++ b/src/lj_crecord.c @@ -1421,7 +1421,9 @@ void LJ_FASTCALL recff_cdata_arith(jit_State *J, RecordFFData *rd) ct = ctype_child(cts, cct); tr = lj_ir_kint(J, (int32_t)ofs); } /* else: interpreter will throw. */ - } /* else: interpreter will throw. */ + } else { + tr = emitir(IRT(IR_ADD, IRT_PTR), tr, lj_ir_kintp(J, sizeof(GCstr))); + } } else if (!tref_isnum(tr)) { tr = 0; }