diff options
| author | granddaifuku <daifukuformac@gmail.com> | 2024-02-11 03:51:26 +0900 |
|---|---|---|
| committer | granddaifuku <daifukuformac@gmail.com> | 2024-02-11 03:51:26 +0900 |
| commit | c4d11083d9ee8efb873cff069b0282be68a37ab2 (patch) | |
| tree | cbdd611b614b91a96c27eea57d052a1021bcf344 | |
| parent | e67b7e02da80cca178a577245bdf92037f3e93df (diff) | |
| download | rust-c4d11083d9ee8efb873cff069b0282be68a37ab2.tar.gz rust-c4d11083d9ee8efb873cff069b0282be68a37ab2.zip | |
fix: ICE when array index exceeds usize
| -rw-r--r-- | clippy_lints/src/indexing_slicing.rs | 1 | ||||
| -rw-r--r-- | tests/ui/crashes/ice-12253.rs | 5 |
2 files changed, 6 insertions, 0 deletions
diff --git a/clippy_lints/src/indexing_slicing.rs b/clippy_lints/src/indexing_slicing.rs index 391db0b0df7..35fcd8cdd35 100644 --- a/clippy_lints/src/indexing_slicing.rs +++ b/clippy_lints/src/indexing_slicing.rs @@ -174,6 +174,7 @@ impl<'tcx> LateLintPass<'tcx> for IndexingSlicing { // only `usize` index is legal in rust array index // leave other type to rustc if let Constant::Int(off) = constant + && off <= usize::MAX as u128 && let ty::Uint(utype) = cx.typeck_results().expr_ty(index).kind() && *utype == ty::UintTy::Usize && let ty::Array(_, s) = ty.kind() diff --git a/tests/ui/crashes/ice-12253.rs b/tests/ui/crashes/ice-12253.rs new file mode 100644 index 00000000000..41f50035144 --- /dev/null +++ b/tests/ui/crashes/ice-12253.rs @@ -0,0 +1,5 @@ +#[allow(overflowing_literals, unconditional_panic, clippy::no_effect)] +fn main() { + let arr: [i32; 5] = [0; 5]; + arr[0xfffffe7ffffffffffffffffffffffff]; +} |
