Skip to content

Commit

Permalink
Auto merge of rust-lang#12266 - granddaifuku:fix/ice-12253-index-exce…
Browse files Browse the repository at this point in the history
…eds-usize, r=Manishearth

fix: ICE when array index exceeds usize

fixes rust-lang#12253

This PR fixes ICE in `indexing_slicing` as it panics when the index of the array exceeds `usize`.

changelog: none
  • Loading branch information
bors committed Feb 12, 2024
2 parents b0e7640 + c4d1108 commit 7dfa6ce
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions clippy_lints/src/indexing_slicing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
5 changes: 5 additions & 0 deletions tests/ui/crashes/ice-12253.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#[allow(overflowing_literals, unconditional_panic, clippy::no_effect)]
fn main() {
let arr: [i32; 5] = [0; 5];
arr[0xfffffe7ffffffffffffffffffffffff];
}

0 comments on commit 7dfa6ce

Please sign in to comment.