Skip to content

Commit f699c8d

Browse files
Kai AldagKai Aldag
Kai Aldag
authored and
Kai Aldag
committed
added bounds checking to NSArray subscript (as stated in the TODO)
added fatalError clause and corrected the if statement Restructured the PR
1 parent a632e37 commit f699c8d

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

Foundation/NSArray.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,8 +344,11 @@ public class NSArray : NSObject, NSCopying, NSMutableCopying, NSSecureCoding, NS
344344

345345
public subscript (idx: Int) -> AnyObject {
346346
get {
347-
// TODO: Bounds checking
348-
return objectAtIndex(idx)
347+
    guard idx < count && idx >= 0 else {
348+
        fatalError("\(self): Index out of bounds")
349+
    }
350+
351+
    return objectAtIndex(idx)
349352
}
350353
}
351354

0 commit comments

Comments
 (0)