mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 14:55:26 +00:00
check index value <= 0xFFFF_FF00
This commit is contained in:
parent
99cb42c296
commit
d3c8e6788c
@ -102,8 +102,12 @@ impl<'tcx> Value<'tcx> {
|
||||
}
|
||||
(PlaceElem::Index(idx), Value::Aggregate { fields, .. }) => {
|
||||
let idx = prop.get_const(idx.into())?.immediate()?;
|
||||
let idx = prop.ecx.read_target_usize(idx).ok()?;
|
||||
fields.get(FieldIdx::from_u32(idx.try_into().ok()?)).unwrap_or(&Value::Uninit)
|
||||
let idx = prop.ecx.read_target_usize(idx).ok()?.try_into().ok()?;
|
||||
if idx <= FieldIdx::MAX_AS_U32 {
|
||||
fields.get(FieldIdx::from_u32(idx)).unwrap_or(&Value::Uninit)
|
||||
} else {
|
||||
return None;
|
||||
}
|
||||
}
|
||||
(
|
||||
PlaceElem::ConstantIndex { offset, min_length: _, from_end: false },
|
||||
|
@ -1,4 +0,0 @@
|
||||
//@ known-bug: #121126
|
||||
fn main() {
|
||||
let _n = 1i64 >> [64][4_294_967_295];
|
||||
}
|
10
tests/ui/indexing/index-bounds.rs
Normal file
10
tests/ui/indexing/index-bounds.rs
Normal file
@ -0,0 +1,10 @@
|
||||
//@ build-fail
|
||||
|
||||
fn main() {
|
||||
let _n = [64][200];
|
||||
//~^ ERROR this operation will panic at runtime [unconditional_panic]
|
||||
|
||||
// issue #121126, test index value between 0xFFFF_FF00 and u32::MAX
|
||||
let _n = [64][u32::MAX as usize - 1];
|
||||
//~^ ERROR this operation will panic at runtime [unconditional_panic]
|
||||
}
|
16
tests/ui/indexing/index-bounds.stderr
Normal file
16
tests/ui/indexing/index-bounds.stderr
Normal file
@ -0,0 +1,16 @@
|
||||
error: this operation will panic at runtime
|
||||
--> $DIR/index-bounds.rs:4:14
|
||||
|
|
||||
LL | let _n = [64][200];
|
||||
| ^^^^^^^^^ index out of bounds: the length is 1 but the index is 200
|
||||
|
|
||||
= note: `#[deny(unconditional_panic)]` on by default
|
||||
|
||||
error: this operation will panic at runtime
|
||||
--> $DIR/index-bounds.rs:8:14
|
||||
|
|
||||
LL | let _n = [64][u32::MAX as usize - 1];
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ index out of bounds: the length is 1 but the index is 4294967294
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
Loading…
Reference in New Issue
Block a user