Skip to content

Commit 305b4bf

Browse files
committed
Merge pull request #15 from KaiCode2/master
Added bounds checking to NSArray subscript
2 parents 9e99edf + f699c8d commit 305b4bf

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)