crosvm/bin/clippy
David Tolnay 4b292afafc clippy: Resolve cast_ptr_alignment
This CL fixes four cases of what I believe are undefined behavior:

  - In vhost where the original code allocates a Vec<u8> with 1-byte
    alignment and casts the Vec's data pointer to a &mut vhost_memory
    which is required to be 8-byte aligned. Underaligned references of
    type &T or &mut T are always undefined behavior in Rust.

  - Same pattern in x86_64.

  - Same pattern in plugin::vcpu.

  - Code in crosvm_plugin that dereferences a potentially underaligned
    pointer. This is always undefined behavior in Rust.

TEST=bin/clippy
TEST=cargo test sys_util

Change-Id: I926f17b1fe022a798f69d738f9990d548f40c59b
Reviewed-on: https://chromium-review.googlesource.com/1566736
Commit-Ready: David Tolnay <dtolnay@chromium.org>
Tested-by: David Tolnay <dtolnay@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: David Tolnay <dtolnay@chromium.org>
2019-04-18 19:51:29 -07:00

50 lines
1 KiB
Bash
Executable file

#!/bin/bash
# Run `cargo clippy` on all Rust code in crosvm with a mindful set of lints
# suppressed.
set -euo pipefail
# Change into directory of script, which is crosvm/bin.
cd "$(dirname "${BASH_SOURCE[0]}")"
# Jump up to root directory of crosvm repo.
cd ..
SUPPRESS=(
# To be resolved.
let_unit_value
question_mark
range_plus_one
unit_arg
# We don't care about these lints. Okay to remain suppressed globally.
blacklisted_name
cast_lossless
cyclomatic_complexity
enum_variant_names
identity_op
len_without_is_empty
len_zero
match_bool
match_wild_err_arm
module_inception
needless_bool
new_without_default
or_fun_call
should_implement_trait
single_char_pattern
too_many_arguments
transmute_ptr_to_ptr
trivially_copy_pass_by_ref
type_complexity
unreadable_literal
useless_let_if_seq
useless_transmute
)
# Needed or else clippy won't re-run on code that has already compiled.
cargo clean
cargo clippy --all-features -- ${SUPPRESS[@]/#/-Aclippy::} "$@"