Skip to content

libc::clock_gettime clock types support is sub-par #1983

Closed
@saethlin

Description

@saethlin

When run with MIRIFLAGS="-Zmiri-disable-isolation -Zmiri-check-number-validity", this program

fn main() {
    let mut tp = std::mem::MaybeUninit::<libc::timespec>::uninit();
    unsafe {
        libc::clock_gettime(libc::CLOCK_MONOTONIC_COARSE, tp.as_mut_ptr());
        tp.assume_init();
    };
}

Emits this:

error: Undefined Behavior: type validation failed at .value.tv_sec: encountered uninitialized bytes, but expected initialized plain (non-pointer) bytes
 --> src/main.rs:5:9
  |
5 |         tp.assume_init();
  |         ^^^^^^^^^^^^^^^^ type validation failed at .value.tv_sec: encountered uninitialized bytes, but expected initialized plain (non-pointer) bytes
  |
  = 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: inside `main` at src/main.rs:5:9

note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace

error: aborting due to previous error

That doesn't seem right to me.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions