Skip to content

memchr signature invites mutability bugs #5276

Description

@RalfJung
pub fn memchr(cx: *const c_void, c: c_int, n: size_t) -> *mut c_void;

The return pointer is derived from the argument pointer cx. If cx is created from a shared reference, that means it is UB to write to the return pointer. Casting const ptr to mut ptr has been involved in a bunch of UB cases, so having that done implicitly by the libc seems pretty bad.

If libc 1.0 APIs can still be changed, I'd strongly recommend using *const for the return type.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions