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-10999] Overflow when trying to get a slice from a Data #3996

Open
swift-ci opened this issue Jun 24, 2019 · 2 comments
Open

[SR-10999] Overflow when trying to get a slice from a Data #3996

swift-ci opened this issue Jun 24, 2019 · 2 comments

Comments

@swift-ci
Copy link
Contributor

Previous ID SR-10999
Radar None
Original Reporter axl411 (JIRA User)
Type Bug
Environment

macOS Mojave 10.14.4

Xcode Version 10.2.1 (10E1001)

Apple Swift version 5.0.1 (swiftlang-1001.0.82.4 clang-1001.0.46.5)
Target: x86_64-apple-darwin18.5.0

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

md5: dfc2f31e6245d08d0b46ba1a18c9848a

Issue Description:

The following code:

import Foundation
 
var data = Data()
(0..<1000).forEach { _ in
    data.append(UInt8.random(in: 0...UInt8.max))
}
 
data[0..<UInt8(9)]
 

...would generate the following error:

Fatal error: Not enough bits to represent the passed value

I would expect the code to work since 0..<Range<UInt8> looks like a valid range for the data.

@belkadan
Copy link

Reproduced. Looks like Data is converting its own range to UInt8 instead of the other way around. @phausler, @millenomi?

@YOCKOW
Copy link
Collaborator

YOCKOW commented Aug 24, 2019

This issue is due to this line.
It is comparatively easy to fix this bug if the type of rangeExpression were only Range or ClosedRange. However, the type of rangeExpression can be PartialRange*, or user-defined type that conforms to RangeExpression whose Bound is not Int. In such cases, it seems impossible to fix it as is.
I mean I think it is necessary to change API (or deprecate this subscript) if we would resolve this problem.

@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

3 participants