diff options
| author | Mike Pall <mike> | 2011-02-06 12:46:18 +0100 |
|---|---|---|
| committer | Mike Pall <mike> | 2011-02-06 12:46:18 +0100 |
| commit | ceece4d13e6da6b96060d7050122f7ed40d75cc9 (patch) | |
| tree | b2ae0be051d0b5e0373dd93645bd9c4e2924e74f | |
| parent | bf58160b7aa21d15b710f948d160da277a02a613 (diff) | |
| download | luajit-ceece4d13e6da6b96060d7050122f7ed40d75cc9.tar.gz luajit-ceece4d13e6da6b96060d7050122f7ed40d75cc9.tar.bz2 luajit-ceece4d13e6da6b96060d7050122f7ed40d75cc9.zip | |
FFI: Perform stricter checks in ffi.cast(). Record ffi.cast().
| -rw-r--r-- | src/lib_ffi.c | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/src/lib_ffi.c b/src/lib_ffi.c index 54d49f87..26e18183 100644 --- a/src/lib_ffi.c +++ b/src/lib_ffi.c | |||
| @@ -406,19 +406,18 @@ LJLIB_CF(ffi_offsetof) | |||
| 406 | return 0; | 406 | return 0; |
| 407 | } | 407 | } |
| 408 | 408 | ||
| 409 | LJLIB_CF(ffi_cast) | 409 | LJLIB_CF(ffi_cast) LJLIB_REC(ffi_new) |
| 410 | { | 410 | { |
| 411 | CTState *cts = ctype_cts(L); | 411 | CTState *cts = ctype_cts(L); |
| 412 | CTypeID id = ffi_checkctype(L, cts); | 412 | CTypeID id = ffi_checkctype(L, cts); |
| 413 | CType *d = ctype_raw(cts, id); | ||
| 413 | TValue *o = lj_lib_checkany(L, 2); | 414 | TValue *o = lj_lib_checkany(L, 2); |
| 414 | L->top = o+1; /* Make sure this is the last item on the stack. */ | 415 | L->top = o+1; /* Make sure this is the last item on the stack. */ |
| 416 | if (!(ctype_isnum(d->info) || ctype_isptr(d->info) || ctype_isenum(d->info))) | ||
| 417 | lj_err_arg(L, 1, LJ_ERR_FFI_INVTYPE); | ||
| 415 | if (!(tviscdata(o) && cdataV(o)->typeid == id)) { | 418 | if (!(tviscdata(o) && cdataV(o)->typeid == id)) { |
| 416 | CTSize sz = lj_ctype_size(cts, id); | 419 | GCcdata *cd = lj_cdata_new(cts, id, d->size); |
| 417 | GCcdata *cd; | 420 | lj_cconv_ct_tv(cts, d, cdataptr(cd), o, CCF_CAST); |
| 418 | if (sz == CTSIZE_INVALID) | ||
| 419 | lj_err_caller(L, LJ_ERR_FFI_INVSIZE); | ||
| 420 | cd = lj_cdata_new(cts, id, sz); /* Create destination cdata. */ | ||
| 421 | lj_cconv_ct_tv(cts, ctype_raw(cts, id), cdataptr(cd), o, CCF_CAST); | ||
| 422 | setcdataV(L, o, cd); | 421 | setcdataV(L, o, cd); |
| 423 | lj_gc_check(L); | 422 | lj_gc_check(L); |
| 424 | } | 423 | } |
