mirror of
https://github.com/apple/swift-collections
synced 2026-11-29 05:14:20 +00:00
[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:
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()
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user