Skip to content

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

Closed
@scottmcm

Description

@scottmcm

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".)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions