Skip to content

Commit 95bd083

Browse files
committed
Update sequence initializations to avoid directly calling mutableCopy which prevents slice offset mismatches
1 parent a04379a commit 95bd083

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

stdlib/public/SDK/Foundation/Data.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1226,7 +1226,11 @@ public struct Data : ReferenceConvertible, Equatable, Hashable, RandomAccessColl
12261226
} else if let buffer = elements as? UnsafeMutableBufferPointer<UInt8> {
12271227
self.init(buffer: buffer)
12281228
} else if let data = elements as? Data {
1229-
self.init(backing: data._backing.mutableCopy(data._sliceRange), range: 0..<data.count)
1229+
let len = data.count
1230+
let backing = data.withUnsafeBytes { (bytes: UnsafePointer<UInt8>) in
1231+
return _DataStorage(bytes: bytes, length: len)
1232+
}
1233+
self.init(backing: backing, range: 0..<len)
12301234
} else {
12311235
let underestimatedCount = elements.underestimatedCount
12321236
self.init(count: underestimatedCount)

0 commit comments

Comments
 (0)