From 4ba7218133e2dd319b20b77e617e6e3233019121 Mon Sep 17 00:00:00 2001 From: Martin Trojer Date: Fri, 27 Jul 2018 07:47:06 -0700 Subject: [PATCH] Added test to verify a NSArray nil insert case. Reviewed By: mbouaziz Differential Revision: D9027638 fbshipit-source-id: 083f0f814 --- .../codetoanalyze/objc/errors/issues.exp | 1 + .../objc/errors/npe/nil_in_array_literal.m | 22 +++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/infer/tests/codetoanalyze/objc/errors/issues.exp b/infer/tests/codetoanalyze/objc/errors/issues.exp index ce034ab65..fb2a2edc4 100644 --- a/infer/tests/codetoanalyze/objc/errors/issues.exp +++ b/infer/tests/codetoanalyze/objc/errors/issues.exp @@ -46,6 +46,7 @@ codetoanalyze/objc/errors/npe/UpdateDict.m, nullable_NSMapTable_objectForKey, 4, codetoanalyze/objc/errors/npe/UpdateDict.m, update_array_with_null, 5, NULL_DEREFERENCE, B1, ERROR, [start of procedure update_array_with_null()] codetoanalyze/objc/errors/npe/UpdateDict.m, update_dict_with_key_null, 10, NULL_DEREFERENCE, B1, ERROR, [start of procedure update_dict_with_key_null(),Skipping dictionaryWithObjectsAndKeys:: method has no implementation] codetoanalyze/objc/errors/npe/WeakCapturedVarsNPE.m, objc_blockWeakCapturedA_strongSelfNoCheck_2, 2, NULL_DEREFERENCE, B1, ERROR, [start of procedure block] +codetoanalyze/objc/errors/npe/nil_in_array_literal.m, Arr_insertNilBad, 3, NULL_DEREFERENCE, B1, ERROR, [start of procedure insertNilBad,start of procedure initA,Taking true branch,return from a call to A_initA] codetoanalyze/objc/errors/npe/nil_in_array_literal.m, Arr_nilInArrayLiteral0, 4, NULL_DEREFERENCE, B1, ERROR, [start of procedure nilInArrayLiteral0] codetoanalyze/objc/errors/npe/nil_in_array_literal.m, Arr_nilInArrayLiteral1, 4, NULL_DEREFERENCE, B1, ERROR, [start of procedure nilInArrayLiteral1] codetoanalyze/objc/errors/npe/nil_in_array_literal.m, Arr_nilInArrayLiteral2, 4, NULL_DEREFERENCE, B1, ERROR, [start of procedure nilInArrayLiteral2] diff --git a/infer/tests/codetoanalyze/objc/errors/npe/nil_in_array_literal.m b/infer/tests/codetoanalyze/objc/errors/npe/nil_in_array_literal.m index b05111068..9ff13e5f0 100644 --- a/infer/tests/codetoanalyze/objc/errors/npe/nil_in_array_literal.m +++ b/infer/tests/codetoanalyze/objc/errors/npe/nil_in_array_literal.m @@ -11,6 +11,21 @@ } @end +@interface A : NSObject { +} +@end + +bool myrand(void); + +@implementation A ++ (instancetype)initA { + if (myrand()) + return nil; + else + return [A new]; +} +@end + @implementation Arr - (void)noProblem { @@ -60,6 +75,13 @@ return foo; } +- (NSMutableArray*)insertNilBad { + NSMutableArray* ar = [NSMutableArray new]; + A* a = [A initA]; + [ar addObject:@[ a ]]; + return ar; +} + @end int ArrMain() {