Skip to content

Commit a1e33e1

Browse files
Require that initializedCount is >= 0 in unsafeUninitializedCapacity (#84917)
Resolves: rdar://162669759
1 parent 90ad689 commit a1e33e1

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

stdlib/public/core/Array.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1549,8 +1549,9 @@ extension Array {
15491549
defer {
15501550
// Update self.count even if initializer throws an error.
15511551
_precondition(
1552-
initializedCount <= _unsafeUninitializedCapacity,
1553-
"Initialized count set to greater than specified capacity."
1552+
UInt(truncatingIfNeeded: initializedCount) <=
1553+
UInt(truncatingIfNeeded: _unsafeUninitializedCapacity),
1554+
"Initialized count must be in 0 ... _unsafeUninitializedCapacity."
15541555
)
15551556
unsafe _precondition(
15561557
buffer.baseAddress == firstElementAddress,

0 commit comments

Comments
 (0)