mirror of
https://github.com/apple/swift-collections
synced 2026-11-25 04:37:48 +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>