Skip to content

Commit 0460763

Browse files
authored
Fix ordered set comparison check (#2082)
For some reason, using `memcmp` with an empty ordered set and a non-empty ordered set returns true: ```swift areOrderedSetsDuplicates([1, 2, 3], []) // true ``` Because of this, we should always check the count before delegating to `memcmp`. We should also be on the lookout for other exceptions in case `memcmp` is not appropriate to use here.
1 parent 8330f53 commit 0460763

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

Sources/ComposableArchitecture/SwiftUI/ForEachStore.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ public struct ForEachStore<
134134
private func areOrderedSetsDuplicates<ID: Hashable>(lhs: OrderedSet<ID>, rhs: OrderedSet<ID>)
135135
-> Bool
136136
{
137+
guard lhs.count == rhs.count else { return false }
137138
var lhs = lhs
138139
var rhs = rhs
139140
if memcmp(&lhs, &rhs, MemoryLayout<OrderedSet<ID>>.size) == 0 {

0 commit comments

Comments
 (0)