]> git.ipfire.org Git - thirdparty/LuaJIT.git/commitdiff
FFI: Limit index range for complex numbers.
authorMike Pall <mike>
Sat, 29 Jan 2011 18:47:37 +0000 (19:47 +0100)
committerMike Pall <mike>
Sat, 29 Jan 2011 18:47:37 +0000 (19:47 +0100)
src/lj_cdata.c
src/lj_crecord.c

index a3257249267c1b42afc6ae6cf8daa9af373d07b2..af78d05e01a1fb1597e41f771973eeb31300a772 100644 (file)
@@ -94,10 +94,12 @@ collect_attrib:
     if (ctype_ispointer(ct->info)) {
       CTSize sz = lj_ctype_size(cts, ctype_cid(ct->info));  /* Element size. */
       if (sz != CTSIZE_INVALID) {
-       if (ctype_isptr(ct->info))
+       if (ctype_isptr(ct->info)) {
          p = (uint8_t *)cdata_getptr(p, ct->size);
-       else if ((ct->info & (CTF_VECTOR|CTF_COMPLEX)))
+       } else if ((ct->info & (CTF_VECTOR|CTF_COMPLEX))) {
+         if ((ct->info & CTF_COMPLEX)) idx &= 1;
          *qual |= CTF_CONST;  /* Valarray elements are constant. */
+       }
        *pp = p + idx*(int32_t)sz;
        return ct;
       }
index 86e9567995bea2338896d0004903544590c9bedc..6121090751fd5f0aacb61f90a3141e543374d29f 100644 (file)
@@ -483,7 +483,10 @@ void LJ_FASTCALL recff_cdata_index(jit_State *J, RecordFFData *rd)
 #endif
   integer_key:
     if (ctype_ispointer(ct->info)) {
-      CTSize sz = lj_ctype_size(cts, (sid = ctype_cid(ct->info)));
+      CTSize sz;
+      if ((ct->info & CTF_COMPLEX))
+       idx = emitir(IRT(IR_BAND, IRT_INTP), idx, lj_ir_kintp(J, 1));
+      sz = lj_ctype_size(cts, (sid = ctype_cid(ct->info)));
       idx = crec_reassoc_ofs(J, idx, &ofs, sz);
       idx = emitir(IRT(IR_MUL, IRT_INTP), idx, lj_ir_kintp(J, sz));
       ptr = emitir(IRT(IR_ADD, IRT_PTR), idx, ptr);