Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unconditional_panic array bounds check doesn't work through Deref #109260

Open
e2-71828 opened this issue Mar 17, 2023 · 1 comment
Open

unconditional_panic array bounds check doesn't work through Deref #109260

e2-71828 opened this issue Mar 17, 2023 · 1 comment
Labels
A-const-eval Area: constant evaluation (mir interpretation) A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. A-mir Area: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.html C-bug Category: This is a bug.

Comments

@e2-71828
Copy link

(Initially reported on URLO)

In the following program:

fn main() {
    let mut arr_0: [u32; 10] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];

    let ptr_0 = Box::new(arr_0);

    let ptr_v = ptr_0[11];
    let arr_v = arr_0[11];
    println!("v:{}", ptr_v);
}

The out-of-bounds access of ptr_0[11] is not flagged at compile time, but the similar access of arr_0[11] is.

@e2-71828 e2-71828 added the C-bug Category: This is a bug. label Mar 17, 2023
@clubby789
Copy link
Contributor

It looks like the MIR ends up as

_7 = const false;
assert(move _7, "index out of bounds: the length is {} but the index is {}", move _6, _5) -> [success: bb2, unwind: bb4];

and the lint isn't able to look through that constant to identify it

@jyn514 jyn514 added A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. A-mir Area: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.html A-const-eval Area: constant evaluation (mir interpretation) labels May 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-const-eval Area: constant evaluation (mir interpretation) A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. A-mir Area: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.html C-bug Category: This is a bug.
Projects
None yet
Development

No branches or pull requests

3 participants