From b3f75da37ef213b5da93a58e2f6bb1881ded0592 Mon Sep 17 00:00:00 2001 From: Jeremy Dubreil Date: Fri, 3 Nov 2017 09:13:58 -0700 Subject: [PATCH] [infer][nullable checker] only report once when the return of a nullable method is derferenced several times Summary: This is to avoid reporting several times the issue. Reviewed By: mbouaziz Differential Revision: D6230418 fbshipit-source-id: e51506c --- infer/src/checkers/NullabilityCheck.ml | 2 +- infer/tests/codetoanalyze/cpp/nullable/issues.exp | 3 +++ infer/tests/codetoanalyze/cpp/nullable/method.cpp | 6 ++++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/infer/src/checkers/NullabilityCheck.ml b/infer/src/checkers/NullabilityCheck.ml index 6f955f96f..daa5a95af 100644 --- a/infer/src/checkers/NullabilityCheck.ml +++ b/infer/src/checkers/NullabilityCheck.ml @@ -122,7 +122,7 @@ module TransferFunctions (CFG : ProcCfg.S) = struct astate | Some (nullable_ap, call_sites) -> report_nullable_dereference nullable_ap call_sites proc_data loc ; - remove_nullable_ap receiver astate ) + assume_pnames_notnull receiver astate ) | Call (Some ret_var, _, _, _, _) -> remove_nullable_ap (ret_var, []) astate | Assign (lhs, rhs, loc) diff --git a/infer/tests/codetoanalyze/cpp/nullable/issues.exp b/infer/tests/codetoanalyze/cpp/nullable/issues.exp index 58c89fc8f..85afffa69 100644 --- a/infer/tests/codetoanalyze/cpp/nullable/issues.exp +++ b/infer/tests/codetoanalyze/cpp/nullable/issues.exp @@ -29,6 +29,9 @@ codetoanalyze/cpp/nullable/method.cpp, methodNotAlwaysCheckedForNullBad, 2, NULL codetoanalyze/cpp/nullable/method.cpp, methodNotAlwaysCheckedForNullBad, 2, NULL_DEREFERENCE, [start of procedure methodNotAlwaysCheckedForNullBad(),Condition is false,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, nullableAssignmentInOneBranchBad, 7, NULLABLE_DEREFERENCE, [deference of &p,assignment of the nullable value,definition of mayReturnNullObject] codetoanalyze/cpp/nullable/method.cpp, nullableAssignmentInOneBranchBad, 7, NULL_DEREFERENCE, [start of procedure nullableAssignmentInOneBranchBad(),Condition is true,start of procedure mayReturnNullObject,Condition is true,return from a call to T_mayReturnNullObject] +codetoanalyze/cpp/nullable/method.cpp, onlyReportOnceBad, 1, NULLABLE_DEREFERENCE, [deference of n$6,definition of mayReturnNullObject] +codetoanalyze/cpp/nullable/method.cpp, onlyReportOnceBad, 1, NULL_DEREFERENCE, [start of procedure onlyReportOnceBad(),start of procedure mayReturnNullObject,Condition is false,return from a call to T_mayReturnNullObject] +codetoanalyze/cpp/nullable/method.cpp, onlyReportOnceBad, 3, NULL_DEREFERENCE, [start of procedure onlyReportOnceBad(),start of procedure mayReturnNullObject,Condition is false,return from a call to T_mayReturnNullObject,start of procedure doSomething,return from a call to T_doSomething,start of procedure mayReturnNullObject,Condition is false,return from a call to T_mayReturnNullObject] codetoanalyze/cpp/nullable/method.cpp, reportsViolationInNotNullElseBranchBad, 1, NULL_TEST_AFTER_DEREFERENCE, [start of procedure reportsViolationInNotNullElseBranchBad(),start of procedure mayReturnNullObject,Condition is false,return from a call to T_mayReturnNullObject,Condition is false] codetoanalyze/cpp/nullable/method.cpp, reportsViolationInNotNullElseBranchBad, 3, NULLABLE_DEREFERENCE, [deference of n$5,definition of mayReturnNullObject] codetoanalyze/cpp/nullable/method.cpp, reportsViolationInNotNullElseBranchBad, 3, NULL_DEREFERENCE, [start of procedure reportsViolationInNotNullElseBranchBad(),start of procedure mayReturnNullObject,Condition is true,return from a call to T_mayReturnNullObject,Condition is false,start of procedure mayReturnNullObject,Condition is false,return from a call to T_mayReturnNullObject] diff --git a/infer/tests/codetoanalyze/cpp/nullable/method.cpp b/infer/tests/codetoanalyze/cpp/nullable/method.cpp index a5a1999d2..8f6d9059a 100644 --- a/infer/tests/codetoanalyze/cpp/nullable/method.cpp +++ b/infer/tests/codetoanalyze/cpp/nullable/method.cpp @@ -123,3 +123,9 @@ void methodNotAlwaysCheckedForNullBad(T* t) { t->mayReturnNullObject()->doSomething(); // reports here } } + +void onlyReportOnceBad(T* t) { + t->mayReturnNullObject()->doSomething(); // reports here + // ... + t->mayReturnNullObject()->doSomething(); // does not report here +}