[BasicContainers] RigidArray.replace(removing:consumingWith:addingCount:initializingWith:): Fix correctness issue with partial initialization

The original code was invoking `_closeGap` with an incorrect size (from `append` rather than `replace`), leading to runtime traps and potential memory safety issues if the `resize` invocation ends up underfilling the container.
This commit is contained in:
Karoy Lorentey committed 2026-04-22 15:32:55 -07:00
1 parent f25e1b38fe
commit d8ace00d14
2 files changed
+86 -1

No files matched your search

@@ -193,7 +193,8 @@ extension RigidArray where Element: ~Copyable {
if c < newItemCount {
self._closeGap(
at: subrange.lowerBound &+ c,
count: capacity &- c)
count: newItemCount &- c)
_count &-= newItemCount &- c
}
span = OutputSpan()
}