Closed
Description
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