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

Replace unaligned pointer deref with read_unaligned #23

Merged
merged 1 commit into from
Feb 22, 2022

Conversation

saethlin
Copy link
Contributor

To deference a pointer, it must be correctly aligned for T. Since there's no alignment check at runtime or enforcement by the type system, this code must use read_unaligned to read the integer's bytes out of the slice. Code like this tends to work fine on x86 because it generally supports unaligned memory access, but may fault on other architectures.

This problem can be demonstrated by running cargo miri test before this PR.

@dermesser dermesser merged commit 8f590d5 into dermesser:master Feb 22, 2022
@dermesser
Copy link
Owner

Thank you for the precaution! On Linux x86_64, it is easy to be myopic to these things

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.

2 participants