From f699c8dd01a124f7c501941bde40ee08a54becbb Mon Sep 17 00:00:00 2001 From: Kai Aldag Date: Thu, 3 Dec 2015 16:08:00 -0800 Subject: [PATCH] added bounds checking to NSArray subscript (as stated in the TODO) added fatalError clause and corrected the if statement Restructured the PR --- Foundation/NSArray.swift | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Foundation/NSArray.swift b/Foundation/NSArray.swift index 38f0c289b2..74e47b80b2 100644 --- a/Foundation/NSArray.swift +++ b/Foundation/NSArray.swift @@ -344,8 +344,11 @@ public class NSArray : NSObject, NSCopying, NSMutableCopying, NSSecureCoding, NS public subscript (idx: Int) -> AnyObject { get { - // TODO: Bounds checking - return objectAtIndex(idx) +     guard idx < count && idx >= 0 else { +         fatalError("\(self): Index out of bounds") +     } + +     return objectAtIndex(idx) } }