Skip to content

Commit

Permalink
Test for null pointer given as arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
DelSkayn committed Feb 13, 2024
1 parent e178dcb commit 3283bb2
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions core/src/value/function/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,17 @@ impl<'a, 'js> Params<'a, 'js> {
argv: *mut qjs::JSValue,
_flags: qjs::c_int,
) -> Self {
let argc = usize::try_from(argc).expect("invalid argument number");
dbg!(
argv,
argc,
std::mem::size_of::<qjs::JSValue>(),
std::mem::align_of::<qjs::JSValue>(),
std::mem::size_of::<*mut qjs::JSValue>()
);
let args = slice::from_raw_parts(argv, argc);
let args = if argv.is_null() {
let argc = usize::try_from(argc).expect("invalid argument number");
slice::from_raw_parts(argv, argc)
} else {
assert_eq!(
argc, 0,
"got a null pointer from quickjs for a non-zero number of args"
);
[].as_slice()
};

Self {
ctx: Ctx::from_ptr(ctx),
function,
Expand Down

0 comments on commit 3283bb2

Please sign in to comment.