[infer][nullable checker] add tests for the early return

Reviewed By: sblackshear

Differential Revision: D6891113

fbshipit-source-id: a614641
master
Jeremy Dubreil 7 years ago committed by Facebook Github Bot
parent 584b10647d
commit 2228f7448d

@ -20,6 +20,8 @@ codetoanalyze/cpp/nullable/method.cpp, methodAlwaysCheckedForNullOkay, 1, NULL_T
codetoanalyze/cpp/nullable/method.cpp, methodAlwaysCheckedForNullOkay, 2, NULL_DEREFERENCE, [start of procedure methodAlwaysCheckedForNullOkay(),Condition is true,start of procedure mayReturnNullObject,Condition is false,return from a call to T_mayReturnNullObject,Condition is true,start of procedure mayReturnNullObject,Condition is false,return from a call to T_mayReturnNullObject]
codetoanalyze/cpp/nullable/method.cpp, methodCallOnFieldOfNullableObjectBad, 2, NULLABLE_DEREFERENCE, [dereference of &p,assignment of the nullable value,definition of mayReturnNullObject]
codetoanalyze/cpp/nullable/method.cpp, methodCallOnFieldOfNullableObjectBad, 2, NULL_DEREFERENCE, [start of procedure methodCallOnFieldOfNullableObjectBad(),start of procedure mayReturnNullObject,Condition is true,return from a call to T_mayReturnNullObject]
codetoanalyze/cpp/nullable/method.cpp, methodCheckedForNullAndReturnOkay, 1, NULL_TEST_AFTER_DEREFERENCE, [start of procedure methodCheckedForNullAndReturnOkay(),start of procedure mayReturnNullObject,Condition is false,return from a call to T_mayReturnNullObject,Condition is false]
codetoanalyze/cpp/nullable/method.cpp, methodCheckedForNullAndReturnOkay, 4, NULL_DEREFERENCE, [start of procedure methodCheckedForNullAndReturnOkay(),start of procedure mayReturnNullObject,Condition is false,return from a call to T_mayReturnNullObject,Condition is false,start of procedure mayReturnNullObject,Condition is false,return from a call to T_mayReturnNullObject]
codetoanalyze/cpp/nullable/method.cpp, methodCheckedForNullOkay, 1, NULL_TEST_AFTER_DEREFERENCE, [start of procedure methodCheckedForNullOkay(),start of procedure mayReturnNullObject,Condition is false,return from a call to T_mayReturnNullObject,Condition is false]
codetoanalyze/cpp/nullable/method.cpp, methodCheckedForNullOkay, 2, NULL_DEREFERENCE, [start of procedure methodCheckedForNullOkay(),start of procedure mayReturnNullObject,Condition is false,return from a call to T_mayReturnNullObject,Condition is true,start of procedure mayReturnNullObject,Condition is false,return from a call to T_mayReturnNullObject]
codetoanalyze/cpp/nullable/method.cpp, methodNotAlwaysCheckedForNullBad, 1, NULL_TEST_AFTER_DEREFERENCE, [start of procedure methodNotAlwaysCheckedForNullBad(),Condition is false,start of procedure mayReturnNullObject,Condition is false,return from a call to T_mayReturnNullObject,Condition is false]

@ -97,6 +97,13 @@ void methodCheckedForNullOkay(T* t) {
}
}
void methodCheckedForNullAndReturnOkay(T* t) {
if (t->mayReturnNullObject() == nullptr) {
return;
}
t->mayReturnNullObject()->doSomething(); // does not report here
}
void reportsViolationOutsideOfNullCheckBad(T* t) {
if (t->mayReturnNullObject() != nullptr) {
t->mayReturnNullObject()->doSomething(); // does not report here

@ -43,6 +43,13 @@ public class NullableViolation {
}
}
void nullableMethodCheckedForNullAndReturnOkay() {
if (returnsNullable() == null) {
return;
}
returnsNullable().doSomething(); // does not report here
}
void dereferenceNullableMethodIncorrectlyCheckedForNullBad() {
if (returnsNullable() == null) {
returnsNullable().doSomething(); // reports here

@ -129,6 +129,16 @@ typedef struct s_ {
return array;
}
- (NSArray*)nullableMethodCheckedForNullAndReturnOkay {
NSObject* nullableObject = [self nullableMethod];
NSArray* array;
if (nullableObject == nil) {
return array;
}
array = @[ nullableObject ]; // does not report here
return array;
}
- (NSArray*)secondElementNullableObjectInNSArrayBad {
NSObject* allocatedObject = [NSObject alloc];
NSObject* nullableObject = [self nullableMethod];

Loading…
Cancel
Save