Skip to content

Commit 551acb3

Browse files
committed
Guard for empty singleton in dictionary builder
1 parent 6216ec6 commit 551acb3

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

stdlib/public/core/DictionaryBuilder.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,13 @@ extension _NativeDictionary {
102102
) -> Int
103103
) {
104104
self.init(capacity: capacity)
105+
106+
// If the capacity is 0, then our storage is the empty singleton. Those are
107+
// read only, so we shouldn't attempt to write to them.
108+
if capacity == 0 {
109+
return
110+
}
111+
105112
let initializedCount = initializer(
106113
UnsafeMutableBufferPointer(start: _keys, count: capacity),
107114
UnsafeMutableBufferPointer(start: _values, count: capacity))

0 commit comments

Comments
 (0)