crosvm/aarch64
Chirantan Ekbote 55bf685478 aarch64: Fix UB in offset__of
This currently gives a compiler warning:

warning: dereferencing a null pointer
   --> aarch64/src/lib.rs:71:19
    |
71  |         unsafe { &(*(0 as *const $str))$(.$field)*  $([$idx])* as *const _ as usize }
    |                   ^^^^^^^^^^^^^^^^^^^^^ this code causes undefined behavior when executed
...
622 |                 arm64_core_reg!(pc)
    |                 ------------------- in this macro invocation
    |
    = note: this warning originates in the macro `offset__of` (in Nightly builds, run with -Z macro-backtrace for more info)

Fix the UB with an implementation based on memoffset::offset_of and
addr_of_mut! instead.

BUG=none
TEST=`emerge-kukui crosvm` no longer complains about UB

Change-Id: I0ab55dc7527c3a4acffe02ee587742dbddd45a0f
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3270099
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Chirantan Ekbote <chirantan@chromium.org>
2021-11-12 01:10:51 +00:00
..
src aarch64: Fix UB in offset__of 2021-11-12 01:10:51 +00:00
.build_test_skip build_test: misc options, improvements, amd bug fixes 2020-10-15 13:40:32 +00:00
Cargo.toml Refactoring: Move various general purpose crates to common/ 2021-10-29 22:31:43 +00:00