std: allocate less memory in current_exe for OpenBSD#158183
Conversation
|
rustbot has assigned @Mark-Simulacrum. Use Why was this reviewer chosen?The reviewer was selected based on:
|
|
it seems a bit over engineered to me : |
|
Yes, but this isn't about an array of characters but of pointers, and |
| @@ -234,11 +234,17 @@ pub fn current_exe() -> io::Result<PathBuf> { | |||
| unsafe { | |||
| let mut mib = [libc::CTL_KERN, libc::KERN_PROC_ARGS, libc::getpid(), libc::KERN_PROC_ARGV]; | |||
There was a problem hiding this comment.
Studying https://man.openbsd.org/sysctl.2#KERN_PROC_ARGS
...So uh is there a reason, since we have to make two sysctl calls, that we don't just ask for KERN_PROC_NARGV the first time?
...though "KERN_PROC_NARGV and KERN_PROC_NENV return the number of elements as an int in the argv or env array." has got to be the most curious phrasing possible for that.
This bug was introduced back in 2f42ac4 when Alex ported the
current_exeimplementation from C to Rust.Vec::with_capacitymeasures capacity in the number of elements, butsysctlmeasures it in bytes, so we need to do some conversions.CC @semarie