File tree Expand file tree Collapse file tree 1 file changed +9
-2
lines changed Expand file tree Collapse file tree 1 file changed +9
-2
lines changed Original file line number Diff line number Diff line change 2
2
//
3
3
// This source file is part of the Swift.org open source project
4
4
//
5
- // Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
5
+ // Copyright (c) 2014 - 2021 Apple Inc. and the Swift project authors
6
6
// Licensed under Apache License v2.0 with Runtime Library Exception
7
7
//
8
8
// See https://swift.org/LICENSE.txt for license information
@@ -286,8 +286,15 @@ extension _SmallString {
286
286
// Restore the memory type of self._storage
287
287
_ = rawPtr. bindMemory ( to: RawBitPattern . self, capacity: 1 )
288
288
}
289
- return try initializer (
289
+ let initializedCount = try initializer (
290
290
UnsafeMutableBufferPointer < UInt8 > ( start: ptr, count: capacity) )
291
+ // Zero-initialize any unused capacity (which could be deinitialized).
292
+ let unusedCapacity = capacity &- initializedCount
293
+ if unusedCapacity > 0 {
294
+ ( rawPtr + initializedCount) . initializeMemory (
295
+ as: UInt8 . self, repeating: 0 , count: unusedCapacity)
296
+ }
297
+ return initializedCount
291
298
}
292
299
self . _invariantCheck ( )
293
300
}
You can’t perform that action at this time.
0 commit comments