Closed
Description
This example prints test 1 2 3
when compiled and run in debug mode:
#![feature(c_variadic)]
extern "C" {
#[no_mangle]
fn vprintf(_: *const libc::c_char, _: ...) -> libc::c_int;
}
#[no_mangle]
unsafe extern "C" fn variadic(fmt: *const libc::c_char, a: ...)
-> libc::c_int {
vprintf(fmt, a)
}
fn main() {
let fmt = std::ffi::CString::new("test %d %d %d\n").expect("new failed");
unsafe {
variadic(fmt.as_ptr(), 1, 2, 3);
}
}
Compiling and running in release mode causes a segfault in glibc/stdio-common/vfprintf.c:1286
because ap
is nul. Enabling debug info in release mode via Cargo.toml
makes the segfault go away.
Meta
$ rustc --version --verbose
rustc 1.35.0-nightly (f22dca0a1 2019-03-05)
binary: rustc
commit-hash: f22dca0a1bef4141e75326caacc3cd59f3d5be8e
commit-date: 2019-03-05
host: x86_64-unknown-linux-gnu
release: 1.35.0-nightly
LLVM version: 8.0