Skip to content

Commit e2a0be8

Browse files
authored
Merge pull request #75266 from swiftlang/susmonteiro/cxx-precondition-oob
Add precondition to prevent out-of-bounds access
2 parents d732513 + 15e1749 commit e2a0be8

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

stdlib/public/Cxx/CxxRandomAccessCollection.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ extension CxxRandomAccessCollection {
4444
// Not using CxxIterator here to avoid making a copy of the collection.
4545
var rawIterator = __beginUnsafe()
4646
rawIterator += RawIterator.Distance(index)
47+
precondition(__endUnsafe() - rawIterator > 0, "C++ iterator access out of bounds")
4748
yield rawIterator.pointee
4849
}
4950
}

0 commit comments

Comments
 (0)