Skip to content

Commit 4544cd1

Browse files
committed
Fix an off-by-one error in the condition of the index method.
1 parent 47eecbd commit 4544cd1

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

stdlib/public/core/RandomAccessCollection.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,9 @@ extension RandomAccessIndexable {
8181
func index(
8282
i: Index, offsetBy n: IndexDistance, limitedBy limit: Index
8383
) -> Index? {
84+
// FIXME: swift-3-indexing-model: tests.
8485
let l = distance(from: i, to: limit)
85-
if n > 0 ? l > 0 && l < n : l <= 0 && n < l {
86+
if n > 0 ? l >= 0 && l < n : l <= 0 && n < l {
8687
return nil
8788
}
8889
return index(i, offsetBy: n)

0 commit comments

Comments
 (0)