aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMike Pall <mike>2011-01-29 19:47:37 +0100
committerMike Pall <mike>2011-01-29 19:47:37 +0100
commit992bc2caa3d84dc9a6beafe3c52c982e01aaa524 (patch)
tree90b4bbd80650732e1bcaba564e9be9421ad81b9f /src
parent6fd721ce7294c0ceba0d0d49a79e59801427ba8d (diff)
downloadluajit-992bc2caa3d84dc9a6beafe3c52c982e01aaa524.tar.gz
luajit-992bc2caa3d84dc9a6beafe3c52c982e01aaa524.tar.bz2
luajit-992bc2caa3d84dc9a6beafe3c52c982e01aaa524.zip
FFI: Limit index range for complex numbers.
Diffstat (limited to 'src')
-rw-r--r--src/lj_cdata.c6
-rw-r--r--src/lj_crecord.c5
2 files changed, 8 insertions, 3 deletions
diff --git a/src/lj_cdata.c b/src/lj_cdata.c
index a3257249..af78d05e 100644
--- a/src/lj_cdata.c
+++ b/src/lj_cdata.c
@@ -94,10 +94,12 @@ collect_attrib:
94 if (ctype_ispointer(ct->info)) { 94 if (ctype_ispointer(ct->info)) {
95 CTSize sz = lj_ctype_size(cts, ctype_cid(ct->info)); /* Element size. */ 95 CTSize sz = lj_ctype_size(cts, ctype_cid(ct->info)); /* Element size. */
96 if (sz != CTSIZE_INVALID) { 96 if (sz != CTSIZE_INVALID) {
97 if (ctype_isptr(ct->info)) 97 if (ctype_isptr(ct->info)) {
98 p = (uint8_t *)cdata_getptr(p, ct->size); 98 p = (uint8_t *)cdata_getptr(p, ct->size);
99 else if ((ct->info & (CTF_VECTOR|CTF_COMPLEX))) 99 } else if ((ct->info & (CTF_VECTOR|CTF_COMPLEX))) {
100 if ((ct->info & CTF_COMPLEX)) idx &= 1;
100 *qual |= CTF_CONST; /* Valarray elements are constant. */ 101 *qual |= CTF_CONST; /* Valarray elements are constant. */
102 }
101 *pp = p + idx*(int32_t)sz; 103 *pp = p + idx*(int32_t)sz;
102 return ct; 104 return ct;
103 } 105 }
diff --git a/src/lj_crecord.c b/src/lj_crecord.c
index 86e95679..61210907 100644
--- a/src/lj_crecord.c
+++ b/src/lj_crecord.c
@@ -483,7 +483,10 @@ void LJ_FASTCALL recff_cdata_index(jit_State *J, RecordFFData *rd)
483#endif 483#endif
484 integer_key: 484 integer_key:
485 if (ctype_ispointer(ct->info)) { 485 if (ctype_ispointer(ct->info)) {
486 CTSize sz = lj_ctype_size(cts, (sid = ctype_cid(ct->info))); 486 CTSize sz;
487 if ((ct->info & CTF_COMPLEX))
488 idx = emitir(IRT(IR_BAND, IRT_INTP), idx, lj_ir_kintp(J, 1));
489 sz = lj_ctype_size(cts, (sid = ctype_cid(ct->info)));
487 idx = crec_reassoc_ofs(J, idx, &ofs, sz); 490 idx = crec_reassoc_ofs(J, idx, &ofs, sz);
488 idx = emitir(IRT(IR_MUL, IRT_INTP), idx, lj_ir_kintp(J, sz)); 491 idx = emitir(IRT(IR_MUL, IRT_INTP), idx, lj_ir_kintp(J, sz));
489 ptr = emitir(IRT(IR_ADD, IRT_PTR), idx, ptr); 492 ptr = emitir(IRT(IR_ADD, IRT_PTR), idx, ptr);