Skip to content

Commit 3f8eb1a

Browse files
committed
Merge remote-tracking branch 'origin/master' into swift-4.0-branch
2 parents d135acf + cab40e7 commit 3f8eb1a

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)