mirror of
https://github.com/apple/swift-collections
synced 2026-11-30 05:18:44 +00:00
When two same-depth internal nodes plus a separator fit in a single node, `concatenateWith` takes the simple-merge branch. The non-leaf subbranch was calling `moveInitializeElements` to move children, but that method operates on the keys/values buffers, not the children buffer. The consequences: - The re-read from `rightHandle.keys[0..<childCount]` hits slots that were already moved-out by the preceding `moveInitializeElements` call, which is UB. - Writes land on top of keys just written by that same prior call, corrupting them. - `self.children` is left with its original (too few) children plus uninitialized slots; subsequent traversal dereferences garbage. - `rightHandle.drop()` deallocates the children buffer without transferring ownership, leaking the `_Node.Storage` references. Fix: call `moveInitializeChildren` instead, matching the splinter branch just above. Add `test_join_nonLeafSimpleMerge`, which builds two depth-1 internal nodes whose combined element count fits in capacity 4 and joins them via `_Node.join`. Without the fix the resulting tree's children are undefined, so iteration either crashes or yields garbage. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Unit tests
Beware! The contents of this directory are not source stable. They are provided as is, with no compatibility promises across package releases. Future versions of this package can arbitrarily change these files or remove them, without any advance notice. (This can include patch releases.)