Merge pull request #575 from lorentey/validate-maximumCount

[RigidArray, RigidDeque].nextSpan: Validate `maximumCount`
This commit is contained in:
Karoy Lorentey authored and GitHub committed 2026-02-16 17:21:24 -08:00
commit 3e505b97bb
16 files changed
+85 -58

No files matched your search

@@ -65,9 +65,7 @@ extension UniqueArray where Element: ~Copyable {
addingCount newItemCount: Int,
initializingWith initializer: (inout OutputSpan<Element>) throws(E) -> Void
) throws(E) -> Void {
precondition(
subrange.lowerBound >= 0 && subrange.upperBound <= self.count,
"Index range out of bounds")
_storage._checkValidBounds(subrange)
precondition(newItemCount >= 0, "Cannot add a negative number of items")
// FIXME: Avoid moving the subsequent elements twice on resize.
_ensureFreeCapacity(newItemCount - subrange.count)
@@ -136,9 +134,7 @@ extension UniqueArray where Element: ~Copyable {
addingCount newItemCount: Int,
initializingWith initializer: (inout OutputSpan<Element>) throws(E) -> Void
) throws(E) -> Void {
precondition(
subrange.lowerBound >= 0 && subrange.upperBound <= self.count,
"Index range out of bounds")
_storage._checkValidBounds(subrange)
precondition(newItemCount >= 0, "Cannot add a negative number of items")
_ensureFreeCapacity(newItemCount - subrange.count)
try _storage._uncheckedReplace(