better range checking
This commit is contained in:
parent
00a9dc03be
commit
9ca48a55bc
28
src/ffi.c
28
src/ffi.c
@ -286,17 +286,7 @@ static u32 styG(B x) {
|
||||
static NOINLINE void ffi_numRange(B x, i32 mode, char* desc, i64 min, i64 max) { // doesn't consume; assumes non-array has already been checked for; if min==max, doesn't check range
|
||||
if (IA(x)==0) return;
|
||||
|
||||
char* ref = mode==1? "&" : mode==0? "*" : ":";
|
||||
B nonNum = nonNumber(x);
|
||||
if (nonNum.u!=m_f64(0).u) thrF("FFI: Array provided for %S%S contained %S", ref, desc, genericDesc(nonNum));
|
||||
|
||||
if (min==max) return;
|
||||
u8 xe = TI(x,elType);
|
||||
incG(x);
|
||||
if (!elNum(xe)) {
|
||||
x = taga(cpyF64Arr(x));
|
||||
xe = TI(x,elType);
|
||||
}
|
||||
i64 emax;
|
||||
switch (xe) {
|
||||
case el_i8: emax=I8_MAX; goto echk;
|
||||
@ -304,15 +294,25 @@ static u32 styG(B x) {
|
||||
case el_i32: emax=I32_MAX; goto echk;
|
||||
echk:;
|
||||
i64 emin = -emax-1;
|
||||
if (emin>=min && emax<=max) goto ok;
|
||||
default:; // fallthrough
|
||||
if (emin>=min && emax<=max) return;
|
||||
// fallthrough, incl. default
|
||||
}
|
||||
|
||||
char* ref = mode==1? "&" : mode==0? "*" : ":";
|
||||
B nonNum = nonNumber(x);
|
||||
if (nonNum.u!=m_f64(0).u) thrF("FFI: Array provided for %S%S contained %S", ref, desc, genericDesc(nonNum));
|
||||
|
||||
if (min==max) return;
|
||||
|
||||
incG(x);
|
||||
if (!elNum(xe)) {
|
||||
x = taga(cpyF64Arr(x));
|
||||
xe = el_f64;
|
||||
}
|
||||
i64 buf[2];
|
||||
if (!getRange_fns[xe](tyany_ptr(x), buf, IA(x))) thrF("FFI: Array provided for %S%S contained non-integer", ref, desc);
|
||||
if (buf[0]<min) thrF("FFI: Array provided for %S%S contained %l", ref, desc, buf[0]);
|
||||
if (buf[1]>max) thrF("FFI: Array provided for %S%S contained %l", ref, desc, buf[1]);
|
||||
|
||||
ok:;
|
||||
decG(x);
|
||||
}
|
||||
static bool elChrOk(B x, u64 max) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user