소스 검색

FFI: Limit index range for complex numbers.

Mike Pall 14 년 전
부모
커밋
992bc2caa3
2개의 변경된 파일8개의 추가작업 그리고 3개의 파일을 삭제
  1. 4 2
      src/lj_cdata.c
  2. 4 1
      src/lj_crecord.c

+ 4 - 2
src/lj_cdata.c

@@ -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;
       }

+ 4 - 1
src/lj_crecord.c

@@ -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);