Replace unaligned pointer deref with read_unaligned by saethlin · Pull Request #23 · dermesser/integer-encoding-rs (original) (raw)
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.