From 3d062c1d5507f0e74e2aba466da76f24316aee0b Mon Sep 17 00:00:00 2001 From: tiif Date: Sun, 5 Jan 2025 01:55:06 +0800 Subject: [PATCH] Add test for fixed args count --- tests/fail-dep/libc/wrong_fixed_arg_count.rs | 14 ++++++++++++++ tests/fail-dep/libc/wrong_fixed_arg_count.stderr | 15 +++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 tests/fail-dep/libc/wrong_fixed_arg_count.stderr diff --git a/tests/fail-dep/libc/wrong_fixed_arg_count.rs b/tests/fail-dep/libc/wrong_fixed_arg_count.rs index e69de29bb2..fdb2e45a0b 100644 --- a/tests/fail-dep/libc/wrong_fixed_arg_count.rs +++ b/tests/fail-dep/libc/wrong_fixed_arg_count.rs @@ -0,0 +1,14 @@ +//@ignore-target: windows # File handling is not implemented yet +//@compile-flags: -Zmiri-disable-isolation +use std::ffi::{CString, OsStr}; +use std::os::unix::ffi::OsStrExt; + +extern "C" { + fn open(path: *const libc::c_char, ...) -> libc::c_int; +} + +fn main() { + let c_path = CString::new(OsStr::new("./text").as_bytes()).expect("CString::new failed"); + let _fd = unsafe { open(c_path.as_ptr(), libc::O_RDWR) }; + //~^ ERROR: incorrect number of fixed args +} diff --git a/tests/fail-dep/libc/wrong_fixed_arg_count.stderr b/tests/fail-dep/libc/wrong_fixed_arg_count.stderr new file mode 100644 index 0000000000..6947ed74c9 --- /dev/null +++ b/tests/fail-dep/libc/wrong_fixed_arg_count.stderr @@ -0,0 +1,15 @@ +error: Undefined Behavior: incorrect number of fixed args for `open/open64`: got 1, expected 2 + --> tests/fail-dep/libc/wrong_fixed_arg_count.rs:LL:CC + | +LL | let _fd = unsafe { open(c_path.as_ptr(), libc::O_RDWR) }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ incorrect number of fixed args for `open/open64`: got 1, expected 2 + | + = help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior + = help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information + = note: BACKTRACE: + = note: inside `main` at tests/fail-dep/libc/wrong_fixed_arg_count.rs:LL:CC + +note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace + +error: aborting due to 1 previous error +