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

[SR-5887] Data crashes when using subscripts with non-zero lower bounds #4066

Open
swift-ci opened this issue Sep 15, 2017 · 4 comments
Open

Comments

@swift-ci
Copy link
Contributor

Previous ID SR-5887
Radar None
Original Reporter chriseidhof (JIRA User)
Type Bug
Environment

Latest Xcode GM (9A235)

Additional Detail from JIRA
Votes 0
Component/s Foundation
Labels Bug
Assignee None
Priority Medium

md5: a40e33dda90e14803763da1dfdb27b81

Issue Description:

When I use the range-based subscript on Data with a non-zero lowerbound, I consistently get a crash.

Example:

 
import Foundation
let data = "hello".data(using: .utf8)! // 5 bytes
data.subdata(in: 1..<3) // this works as expected
data[1..<3] // this crashes

The subscript works fine when the lowerbound is zero.

@swift-ci
Copy link
Contributor Author

Comment by Chris Eidhof (JIRA)

Other methods are broken as well:

data.suffix(from: 1)

@swift-ci
Copy link
Contributor Author

Comment by Chris Eidhof (JIRA)

Ok, the plot thickens. It turns out this only happens in a playground. Probably a playground-quicklookable problem.

@swift-ci
Copy link
Contributor Author

Comment by Chris Eidhof (JIRA)

I'm pretty sure this line is the culprit:

https://github.com/apple/swift/blob/master/stdlib/public/SDK/Foundation/Data.swift#L1773

It should almost certainly use startIndex, not 0.

@belkadan
Copy link

@phausler

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants