Model NSArray::arrayWithObject

Summary:public
This models [NSArray arrayWithObject:o] to require [o] to be non-nil,
reporting NULL_DEREFERENCE otherwise.

Reviewed By: jvillard

Differential Revision: D2968563

fb-gh-sync-id: 04ae123
shipit-source-id: 04ae123
master
Josh Berdine 9 years ago committed by Facebook Github Bot 1
parent 0a32ff4400
commit 97cb854e5c

@ -15,4 +15,9 @@
return [NSArray alloc];
}
+ (instancetype)arrayWithObject:(char*)anObject {
char _ = *anObject;
return [NSArray alloc];
}
@end

@ -19,6 +19,10 @@
NSArray* foo = @[ @"aaa", @"bbb" ];
// check that array literals create valid objects
NSArray* foofoo = @[ foo ];
NSArray* bar = [NSArray arrayWithObject:@"ccc"];
// test return value of arrayWithObject to avoid RETURN_VALUE_IGNORED report
if (bar)
return;
}
- (void)nilInArrayLiteral0 {
@ -49,11 +53,21 @@
NSArray* foo = @[ @"aaa", @"bbb", str ];
}
- (NSArray*)nilInArrayWithObject {
NSString* str = nil;
// nil argument in arrayWithObject crashes
NSArray* foo = [NSArray arrayWithObject:str];
return foo;
}
@end
int main() {
A* a = [A alloc];
[a noProblem];
[a nilInArrayLiteral0];
[a nilInArrayWithObject];
return 0;
}

@ -63,7 +63,8 @@ public class NPEArrayLiteralTest {
"nilInArrayLiteral0",
"nilInArrayLiteral1",
"nilInArrayLiteral2",
"nilInArrayLiteral3"
"nilInArrayLiteral3",
"nilInArrayWithObject"
};
assertThat(
"Only NPE should be found", inferResults,

Loading…
Cancel
Save