don't construct nullptr cstring
This commit is contained in:
parent
b3a16d49bc
commit
8bd07cccaa
|
@ -204,10 +204,17 @@ pub fn execv(command: impl AsRef<Path>, args: &[&str]) -> Result<()> {
|
|||
args_cstr.push(cur_arg_cstr);
|
||||
}
|
||||
|
||||
// NOTE: The last arg must be a null pointer. We construct a CString from the raw pointer.
|
||||
args_cstr.push(unsafe { CString::from_raw(std::ptr::null_mut()) });
|
||||
// NOTE: The last arg must be a null pointer, but we can't construct a CString from nullptr, so
|
||||
// we construct an array of pointers and use that
|
||||
let args_ptrs: Vec<_> = args
|
||||
.iter()
|
||||
.map(|s| s.as_ptr())
|
||||
.chain(std::iter::once(std::ptr::null()))
|
||||
.collect();
|
||||
|
||||
if unsafe { libc::execv(command_cstr.as_ptr().cast(), args_cstr.as_ptr().cast()) } == -1 {
|
||||
dbg!(&command_cstr, &args_ptrs);
|
||||
|
||||
if unsafe { libc::execv(command_cstr.as_ptr().cast(), args_ptrs.as_ptr().cast()) } == -1 {
|
||||
return ctx_os_error(format_args!(
|
||||
"error calling exec({command}, {args:?})",
|
||||
command = command.display()
|
||||
|
|
Loading…
Reference in New Issue