Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve safety & usability of |size_t| and |ssize_t|. #29222

Closed
wants to merge 4 commits into from

Conversation

briansmith
Copy link
Contributor

This has been rebased on top of #28779 and #29220. It is intended to address the usize/isize related aspects of RFC 1291.

Note in particular that one of these changesets removes casts that would actually result in unsafe memory usage on any platform where libc::size_t is smaller than usize.

r? @alexcrichton

@rust-highfive
Copy link
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @alexcrichton (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. The way Github handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@briansmith
Copy link
Contributor Author

@bors r? @alexcrichton

@bors
Copy link
Contributor

bors commented Oct 22, 2015

☔ The latest upstream changes (presumably #29045) made this pull request unmergeable. Please resolve the merge conflicts.

Also, improve the documentation related to the range of usize and
isize.
Since |usize| may be larger than |libc::size_t|, it is generally not safe to
cast from |usize| to |libc::size_t|.

The effect of this commit is to cause the build to fail on a platform where
`libc::size_t` isn't the same as `usize`. But, that is better than the current
state of affairs, where unsafe truncations can occur on such platforms,
potentially leading to buffer overflows and other unsafety.
I didn't try to find every such cast. I concentrated on the files that
had now-unnecessary casts from |usize| to |size_t|.
@briansmith
Copy link
Contributor Author

This is now against the wrong repo.

@briansmith briansmith closed this Oct 22, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants