[SR-13563] Data.advanced(by:)
crashes when result Data
would be empty
#3970
Labels
Data.advanced(by:)
crashes when result Data
would be empty
#3970
Attachment: Download
Additional Detail from JIRA
md5: 44b2af155ee2643aca628d439789b4cb
Issue Description:
A `Data` can be constructed empty: The expression `let data = Data()` is valid and does not crash.
Supporting an empty `Data` is useful. It allows for consistent and generic code that doesn't need to consider additional details when a source of data has become exhausted, or when there is no data to work with.
It seems reasonable to expect that the method `advanced(by🙂` on `Data` should be able to handle a case where the resulting `Data` will be empty.
However, these examples crash:
```
let data1 = Data().advanced(by:0)
let data2 = Data([UInt8()]).advanced(by:1)
```
The error is:
"error: Execution was interrupted, reason: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0). The process has been left at the point where it was interrupted, use "thread return -x" to return to the state before expression evaluation."
I've attached a playground screen shot that shows more detail about the crash being in `Foundation.Data.advanced(by🙂`.
This happens in Playgrounds and Xcode unit tests. I've not tested other platforms.
The text was updated successfully, but these errors were encountered: