@@ -2176,28 +2176,29 @@ final internal class _HashableTypedNativeDictionaryStorage<Key: Hashable, Value>
2176
2176
_ objects: UnsafeMutablePointer < AnyObject > ? ,
2177
2177
andKeys keys: UnsafeMutablePointer < AnyObject > ? ,
2178
2178
count: Int ) {
2179
+ _precondition ( count >= 0 , " Invalid count " )
2179
2180
// The user is expected to provide a storage of the correct size
2180
2181
if let unmanagedKeys = _UnmanagedAnyObjectArray ( keys) {
2181
2182
if let unmanagedObjects = _UnmanagedAnyObjectArray ( objects) {
2182
2183
// keys nonnull, objects nonnull
2183
2184
for (offset: i, element: ( key: key, value: val) ) in full. enumerated ( ) {
2185
+ guard i < count else { break }
2184
2186
unmanagedObjects [ i] = _bridgeAnythingToObjectiveC ( val)
2185
2187
unmanagedKeys [ i] = _bridgeAnythingToObjectiveC ( key)
2186
- guard i < count else { break }
2187
2188
}
2188
2189
} else {
2189
2190
// keys nonnull, objects null
2190
2191
for (offset: i, element: ( key: key, value: _) ) in full. enumerated ( ) {
2191
- unmanagedKeys [ i] = _bridgeAnythingToObjectiveC ( key)
2192
2192
guard i < count else { break }
2193
+ unmanagedKeys [ i] = _bridgeAnythingToObjectiveC ( key)
2193
2194
}
2194
2195
}
2195
2196
} else {
2196
2197
if let unmanagedObjects = _UnmanagedAnyObjectArray ( objects) {
2197
2198
// keys null, objects nonnull
2198
2199
for (offset: i, element: ( key: _, value: val) ) in full. enumerated ( ) {
2199
- unmanagedObjects [ i] = _bridgeAnythingToObjectiveC ( val)
2200
2200
guard i < count else { break }
2201
+ unmanagedObjects [ i] = _bridgeAnythingToObjectiveC ( val)
2201
2202
}
2202
2203
} else {
2203
2204
// do nothing, both are null
@@ -2969,6 +2970,7 @@ final internal class _SwiftDeferredNSDictionary<Key: Hashable, Value>
2969
2970
_ keys: UnsafeMutablePointer < AnyObject > ? ,
2970
2971
_ count: Int
2971
2972
) {
2973
+ _precondition ( count >= 0 , " Invalid count " )
2972
2974
bridgeEverything ( )
2973
2975
// The user is expected to provide a storage of the correct size
2974
2976
var i = 0 // Position in the input storage
@@ -2979,19 +2981,19 @@ final internal class _SwiftDeferredNSDictionary<Key: Hashable, Value>
2979
2981
// keys nonnull, objects nonnull
2980
2982
for position in 0 ..< bucketCount {
2981
2983
if bridgedBuffer. isInitializedEntry ( at: position) {
2984
+ guard i < count else { break }
2982
2985
unmanagedObjects [ i] = bridgedBuffer. value ( at: position)
2983
2986
unmanagedKeys [ i] = bridgedBuffer. key ( at: position)
2984
2987
i += 1
2985
- guard i < count else { break }
2986
2988
}
2987
2989
}
2988
2990
} else {
2989
2991
// keys nonnull, objects null
2990
2992
for position in 0 ..< bucketCount {
2991
2993
if bridgedBuffer. isInitializedEntry ( at: position) {
2994
+ guard i < count else { break }
2992
2995
unmanagedKeys [ i] = bridgedBuffer. key ( at: position)
2993
2996
i += 1
2994
- guard i < count else { break }
2995
2997
}
2996
2998
}
2997
2999
}
@@ -3000,9 +3002,9 @@ final internal class _SwiftDeferredNSDictionary<Key: Hashable, Value>
3000
3002
// keys null, objects nonnull
3001
3003
for position in 0 ..< bucketCount {
3002
3004
if bridgedBuffer. isInitializedEntry ( at: position) {
3005
+ guard i < count else { break }
3003
3006
unmanagedObjects [ i] = bridgedBuffer. value ( at: position)
3004
3007
i += 1
3005
- guard i < count else { break }
3006
3008
}
3007
3009
}
3008
3010
} else {
0 commit comments