rust-lang / rust-lang/libc

memchr signature invites mutability bugs

Open
#5,276 10 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
2.6k
Forks
1.3k
Avg merge
1d 22h
Merged PRs (30d)
69

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the libc memchr binding shown in the issue and trace its platform-specific declarations and uses. Check whether changing the return pointer to *const c_void is compatible across the supported APIs, then verify that the binding and any affected tests or examples consistently reflect the const return type.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
api
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.