@@ -2138,28 +2138,29 @@ final internal class _HashableTypedNativeDictionaryStorage<Key: Hashable, Value>
2138
2138
_ objects: UnsafeMutablePointer < AnyObject > ? ,
2139
2139
andKeys keys: UnsafeMutablePointer < AnyObject > ? ,
2140
2140
count: Int ) {
2141
+ _precondition ( count >= 0 , " Invalid count " )
2141
2142
// The user is expected to provide a storage of the correct size
2142
2143
if let unmanagedKeys = _UnmanagedAnyObjectArray ( keys) {
2143
2144
if let unmanagedObjects = _UnmanagedAnyObjectArray ( objects) {
2144
2145
// keys nonnull, objects nonnull
2145
2146
for (offset: i, element: ( key: key, value: val) ) in full. enumerated ( ) {
2147
+ guard i < count else { break }
2146
2148
unmanagedObjects [ i] = _bridgeAnythingToObjectiveC ( val)
2147
2149
unmanagedKeys [ i] = _bridgeAnythingToObjectiveC ( key)
2148
- guard i < count else { break }
2149
2150
}
2150
2151
} else {
2151
2152
// keys nonnull, objects null
2152
2153
for (offset: i, element: ( key: key, value: _) ) in full. enumerated ( ) {
2153
- unmanagedKeys [ i] = _bridgeAnythingToObjectiveC ( key)
2154
2154
guard i < count else { break }
2155
+ unmanagedKeys [ i] = _bridgeAnythingToObjectiveC ( key)
2155
2156
}
2156
2157
}
2157
2158
} else {
2158
2159
if let unmanagedObjects = _UnmanagedAnyObjectArray ( objects) {
2159
2160
// keys null, objects nonnull
2160
2161
for (offset: i, element: ( key: _, value: val) ) in full. enumerated ( ) {
2161
- unmanagedObjects [ i] = _bridgeAnythingToObjectiveC ( val)
2162
2162
guard i < count else { break }
2163
+ unmanagedObjects [ i] = _bridgeAnythingToObjectiveC ( val)
2163
2164
}
2164
2165
} else {
2165
2166
// do nothing, both are null
@@ -2942,6 +2943,7 @@ final internal class _SwiftDeferredNSDictionary<Key: Hashable, Value>
2942
2943
_ keys: UnsafeMutablePointer < AnyObject > ? ,
2943
2944
_ count: Int
2944
2945
) {
2946
+ _precondition ( count >= 0 , " Invalid count " )
2945
2947
bridgeEverything ( )
2946
2948
// The user is expected to provide a storage of the correct size
2947
2949
var i = 0 // Position in the input storage
@@ -2952,19 +2954,19 @@ final internal class _SwiftDeferredNSDictionary<Key: Hashable, Value>
2952
2954
// keys nonnull, objects nonnull
2953
2955
for position in 0 ..< bucketCount {
2954
2956
if bridgedBuffer. isInitializedEntry ( at: position) {
2957
+ guard i < count else { break }
2955
2958
unmanagedObjects [ i] = bridgedBuffer. value ( at: position)
2956
2959
unmanagedKeys [ i] = bridgedBuffer. key ( at: position)
2957
2960
i += 1
2958
- guard i < count else { break }
2959
2961
}
2960
2962
}
2961
2963
} else {
2962
2964
// keys nonnull, objects null
2963
2965
for position in 0 ..< bucketCount {
2964
2966
if bridgedBuffer. isInitializedEntry ( at: position) {
2967
+ guard i < count else { break }
2965
2968
unmanagedKeys [ i] = bridgedBuffer. key ( at: position)
2966
2969
i += 1
2967
- guard i < count else { break }
2968
2970
}
2969
2971
}
2970
2972
}
@@ -2973,9 +2975,9 @@ final internal class _SwiftDeferredNSDictionary<Key: Hashable, Value>
2973
2975
// keys null, objects nonnull
2974
2976
for position in 0 ..< bucketCount {
2975
2977
if bridgedBuffer. isInitializedEntry ( at: position) {
2978
+ guard i < count else { break }
2976
2979
unmanagedObjects [ i] = bridgedBuffer. value ( at: position)
2977
2980
i += 1
2978
- guard i < count else { break }
2979
2981
}
2980
2982
}
2981
2983
} else {
0 commit comments