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

str::get isn't overflow-checked with InclusiveRange #42401

Closed
scottmcm opened this issue Jun 3, 2017 · 0 comments
Closed

str::get isn't overflow-checked with InclusiveRange #42401

scottmcm opened this issue Jun 3, 2017 · 0 comments

Comments

@scottmcm
Copy link
Member

scottmcm commented Jun 3, 2017

Repro: https://is.gd/lVsdTA

#![feature(inclusive_range_syntax)]
#![feature(str_checked_slicing)]

fn main(){
    println!("{:?}", &"hello".get(...usize::max_value()-1)); // None
    println!("{:?}", &"hello".get(...usize::max_value())); // Some("")
}

(The latter with [] correctly panics with "attempted to index str up to maximum usize".)

scottmcm added a commit to scottmcm/rust that referenced this issue Jun 4, 2017
frewsxcv added a commit to frewsxcv/rust that referenced this issue Jun 13, 2017
Add overflow checking for `str::get` with inclusive ranges

Fixes rust-lang#42401

Two commits here:

1. The first makes `str::index` just call `SliceIndex<str>::index`.  It's intended to have no behavior change, except where the two methods were inconsistent.
2. The second actually adds the overflow checking to `get(_mut)` (and tests for it)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants