mirror of
https://github.com/apple/swift-collections
synced 2026-11-24 04:27:53 +00:00
When the updater closure removes an existing entry (sets the value to nil), `UniqueDictionary.updateValue(forKey:with:)` called `_removeValue(at:)`. But the value had already been moved out of its slot before calling the updater, and `_removeValue(at:)` moves it out again and discards the result, destroying uninitialized memory. This leads to crashes or memory corruption. `RigidDictionary.updateValue(forKey:with:)` already handles this case correctly, by deinitializing just the key and resolving the hole. Add `UniqueDictionary._removeEntry(withMovedValueAt:)`, which does the same and then shrinks storage under the same condition as `_removeValue(at:)`, and use it for the removal path.