From 3283bb211a59d8a0e67b38a3c943fc53f9334c6f Mon Sep 17 00:00:00 2001 From: Mees Delzenne Date: Tue, 13 Feb 2024 17:13:03 +0100 Subject: [PATCH] Test for null pointer given as arguments --- core/src/value/function/params.rs | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/core/src/value/function/params.rs b/core/src/value/function/params.rs index 53df24d8..28227422 100644 --- a/core/src/value/function/params.rs +++ b/core/src/value/function/params.rs @@ -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::(), - std::mem::align_of::(), - 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,