Skip to content

Commit cab40e7

Browse files
authored
Merge pull request swiftlang#1155 from mattrajca/master
2 parents c65abfe + adcbaf3 commit cab40e7

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

Foundation/FileHandle.swift

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,16 @@ open class FileHandle : NSObject, NSSecureCoding {
103103
dynamicBuffer = _CFReallocf(dynamicBuffer!, total)
104104
}
105105

106-
if (0 == total) {
106+
if total == 0 {
107107
free(dynamicBuffer)
108108
}
109-
110-
if total > 0 {
109+
else if total > 0 {
111110
let bytePtr = dynamicBuffer!.bindMemory(to: UInt8.self, capacity: total)
112-
return Data(bytesNoCopy: bytePtr, count: total, deallocator: .none)
111+
return Data(bytesNoCopy: bytePtr, count: total, deallocator: .free)
112+
}
113+
else {
114+
assertionFailure("The total number of read bytes must not be negative")
115+
free(dynamicBuffer)
113116
}
114117

115118
return Data()

0 commit comments

Comments
 (0)