You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I haven't been able to pinpoint the problem exactly so far but in some cases Data.replaceSubrange can lead to an empty Data object.
vardata = Data(bytes: [0x01, 0x02])
vardataI = datadataI.replaceSubrange(0..<1, with: Data()) // Works as expected: [0x02]vardataII = Data(base64Encoded: data.base64EncodedString())!
dataII.replaceSubrange(0..<1, with: Data()) // BUG: result is empty, 0 bytesvardataIII = Data(base64Encoded: data.base64EncodedString())!
dataIII.replaceSubrange(0..<1, with: []) // Works again: [0x02]
In the code above, replacing the first byte with empty Data (aka removing it) only works in case I and III. The code only varies in how the modified Data object and the replacing data are constructed.
In our production code the original data object got constructed by using the empty initializer and by appending data constructed with init(bytes: UnsafeRawPointer, count: Int) by calling append(_ other: Data). So there seems to be some variation in how this bug is triggered.
The code above (case II) worked with Swift 3.0 / Xcode 8.2.1. We worked around the problem now by using the code in case III above.
The text was updated successfully, but these errors were encountered:
Environment
Xcode 8.3 (8E162)
Swift 3.1
Additional Detail from JIRA
md5: 5d2fb4c51b6ac4475003ac5b9e037656
Issue Description:
I haven't been able to pinpoint the problem exactly so far but in some cases
Data.replaceSubrange
can lead to an emptyData
object.In the code above, replacing the first byte with empty
Data
(aka removing it) only works in case I and III. The code only varies in how the modified Data object and the replacing data are constructed.In our production code the original data object got constructed by using the empty initializer and by appending data constructed with
init(bytes: UnsafeRawPointer, count: Int)
by callingappend(_ other: Data)
. So there seems to be some variation in how this bug is triggered.The code above (case II) worked with Swift 3.0 / Xcode 8.2.1. We worked around the problem now by using the code in case III above.
The text was updated successfully, but these errors were encountered: