Skip to content

Autoharness: support &CStr arguments under --bounded-arguments #4803

Description

@srivatsansamraj

Requested feature: autoharness support for &CStr arguments under --bounded-arguments, alongside &[T] and &str.

Use case: on a whole-library verify-std run, 67 functions are skipped for a missing Arbitrary implementation on a &CStr argument, 23 of them in core (CStr::to_bytes, to_str, count_bytes, the PartialEq/Ord impls, and the rest of the CStr API).

Link to relevant documentation (Rust reference, Nomicon, RFC): https://doc.rust-lang.org/core/ffi/struct.CStr.html

A &CStr is the bytes of nondeterministic storage up to its first NUL, so it can be generated the way any_str_ref generates a &str: set the last byte of the storage to NUL and take from_bytes_until_nul, a deterministic function of the nondeterministic bytes that satisfies the invariant by construction. Slice bound, less one for the NUL.

Test case:

use std::ffi::CStr;

// Skipped: "Missing Arbitrary implementation for argument(s) s: &std::ffi::CStr".
// Expected: "Requires --bounded-arguments" without the flag; a harness once it is
// passed, and this one fails on the empty C string.
pub fn first(s: &CStr) -> u8 {
    s.to_bytes()[0]
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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