Skip to content

Crash in BidirectionalCollection.firstRange(of:) #666

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

Closed
bjhomer opened this issue Feb 28, 2023 · 6 comments
Closed

Crash in BidirectionalCollection.firstRange(of:) #666

bjhomer opened this issue Feb 28, 2023 · 6 comments
Labels
bug Something isn't working

Comments

@bjhomer
Copy link

bjhomer commented Feb 28, 2023

Description
BidirectionalCollection.firstRange(of:) crashes when the last element of the needle matches the last element of the haystack, but other elements do not match.

Steps to reproduce

let array = [1, 2, 3]
array.firstRange(of: [1, 3]) // Crash: index out of bounds

let str = "abc"
str.firstRange(of: "zc") // Crash: index out of bounds

Expected behavior
The above examples should not crash, but should instead return nil

Environment

$ swiftc -version
swift-driver version: 1.62.15 Apple Swift version 5.7.2 (swiftlang-5.7.2.135.5 clang-1400.0.29.51)
Target: arm64-apple-macosx13.0

Also seems to happen in Swift 5.8 (in the Xcode beta)

swiftc -version
$ swift-driver version: 1.75.1 Apple Swift version 5.8 (swiftlang-5.8.0.117.11 clang-1403.0.22.8.60)
Target: arm64-apple-macosx13.0
@bjhomer bjhomer added the bug Something isn't working label Feb 28, 2023
@stephentyrone
Copy link
Contributor

I believe that this is fixed in 5.8 and main with #631. Note that this is a runtime fix, so testing with the Xcode beta on a version of macOS with the 5.7 runtime is expected not to work.

@AnthonyLatsis
Copy link

@natecook1000 Could you transfer this issue to the string processing repo?

@stephentyrone
Copy link
Contributor

stephentyrone commented Mar 17, 2023

Given that it’s already fixed, are we cloning it just to close immediately, or is there a further problem to address?

@AnthonyLatsis
Copy link

AnthonyLatsis commented Mar 17, 2023

or is there a further problem to address?

No, just seeing to it that issues end up in the right repos, even if they happen to be fixed by the time they do. It’s fine to close prior to transferring.

@AnthonyLatsis
Copy link

@natecook1000 ping

@natecook1000 natecook1000 transferred this issue from swiftlang/swift Apr 20, 2023
@natecook1000
Copy link
Member

Steve's right, this was addressed by #631. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants