jit: Add NULL as terminating argv

This commit is contained in:
CohenArthur 2020-08-22 11:24:02 +02:00
parent e64f523b27
commit 2a14fb7bf2

View File

@ -82,8 +82,11 @@ pub(super) fn run_jit(tcx: TyCtxt<'_>) -> ! {
.chain(args.split(" "))
.map(|arg| CString::new(arg).unwrap())
.collect::<Vec<_>>();
let argv = args.iter().map(|arg| arg.as_ptr()).collect::<Vec<_>>();
// TODO: Rust doesn't care, but POSIX argv has a NULL sentinel at the end
let mut argv = args.iter().map(|arg| arg.as_ptr()).collect::<Vec<_>>();
// Push a null pointer as a terminating argument. This is required by POSIX and
// useful as some dynamic linkers use it as a marker to jump over.
argv.push(std::ptr::null());
let ret = f(args.len() as c_int, argv.as_ptr());