Skip to content

Commit

Permalink
[param-not-null] Do not report on parameters of blocks
Browse files Browse the repository at this point in the history
Summary: There are cases where reporting on parameters of blocks is not wanted, however those parameters are not always annotated with Nonnull. So we'll stop reporting for them. We can still report when block parameters captured from the parent methods are executed within a block.

Reviewed By: geralt-encore

Differential Revision: D65340747

fbshipit-source-id: 43e1c96aa41518f4db0cab8d4b292ae95d27855b
  • Loading branch information
dulmarod authored and facebook-github-bot committed Nov 1, 2024
1 parent a19e6ce commit 530e0b8
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 6 deletions.
6 changes: 3 additions & 3 deletions infer/src/checkers/ParameterNotNullChecked.ml
Original file line number Diff line number Diff line change
Expand Up @@ -282,9 +282,9 @@ let init_block_params
let checker ({IntraproceduralAnalysis.proc_desc} as analysis_data) =
let attributes = Procdesc.get_attributes proc_desc in
let captured_formals_attributes = get_captured_formals attributes in
let formals_attributes =
List.map ~f:(fun formal -> (formal, attributes, false)) attributes.ProcAttributes.formals
in
let procname = Procdesc.get_proc_name proc_desc in
let formals = if Procname.is_objc_block procname then [] else attributes.ProcAttributes.formals in
let formals_attributes = List.map ~f:(fun formal -> (formal, attributes, false)) formals in
let initial_blockParams, initTraceInfo =
init_block_params (List.append formals_attributes captured_formals_attributes)
in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ typedef void (^NewAnnotateBlock1)(const char* _Nullable key,

void MarkerAnnotateSync1(NS_NOESCAPE _Nullable NewAnnotateSyncBlock1 block) {}

void testAnnotateOk_FP(NSString* composerSessionID) {
void testAnnotateOk(NSString* composerSessionID) {
MarkerAnnotateSync1(^(NewAnnotateBlock1 annotate) {
annotate("composer_session_id", composerSessionID);
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
codetoanalyze/objc/parameter-not-null-checked/Blocks_as_parameters.m, objc_block_Blocks_as_parameters.m:16, 1, BLOCK_PARAMETER_NOT_NULL_CHECKED, no_bucket, WARNING, [Parameter `annotate` of objc_block_Blocks_as_parameters.m:16,Executing `annotate`], "annotate("=>"BLOCK_CALL_SAFE(annotate, "@17:5
codetoanalyze/objc/parameter-not-null-checked/Blocks_as_parameters.m, Blocks_as_parameters.blockNotCheckedBad:and:, 1, BLOCK_PARAMETER_NOT_NULL_CHECKED, no_bucket, WARNING, [Parameter `block` of Blocks_as_parameters.blockNotCheckedBad:and:,Executing `block`], "block("=>"BLOCK_CALL_SAFE(block"@32:3
codetoanalyze/objc/parameter-not-null-checked/Blocks_as_parameters.m, Blocks_as_parameters.blockNotCheckedBad1:and:, 1, BLOCK_PARAMETER_NOT_NULL_CHECKED, no_bucket, WARNING, [Parameter `block` of Blocks_as_parameters.blockNotCheckedBad1:and:,Executing `block`], "block("=>"BLOCK_CALL_SAFE(block, "@36:3
codetoanalyze/objc/parameter-not-null-checked/Blocks_as_parameters.m, Blocks_as_parameters.twoBlocksNotCheckedBad:and:and:, 2, BLOCK_PARAMETER_NOT_NULL_CHECKED, no_bucket, WARNING, [Parameter `block1` of Blocks_as_parameters.twoBlocksNotCheckedBad:and:and:,Executing `block1`], "block1("=>"BLOCK_CALL_SAFE(block1"@53:5
codetoanalyze/objc/parameter-not-null-checked/Blocks_as_parameters.m, Blocks_as_parameters.twoBlocksNotCheckedBad:and:and:, 3, BLOCK_PARAMETER_NOT_NULL_CHECKED, no_bucket, WARNING, [Parameter `block2` of Blocks_as_parameters.twoBlocksNotCheckedBad:and:and:,Executing `block2`], "block2("=>"BLOCK_CALL_SAFE(block2"@54:5
codetoanalyze/objc/parameter-not-null-checked/Blocks_as_parameters.m, Blocks_as_parameters.nonnullBlockTwoBlocksBad:and:and:, 4, BLOCK_PARAMETER_NOT_NULL_CHECKED, no_bucket, WARNING, [Parameter `block2` of Blocks_as_parameters.nonnullBlockTwoBlocksBad:and:and:,Executing `block2`], "block2("=>"BLOCK_CALL_SAFE(block2"@82:3
codetoanalyze/objc/parameter-not-null-checked/Blocks_as_parameters.m, Blocks_as_parameters.blockCheckedAssignNULLBad:and:, 3, BLOCK_PARAMETER_NOT_NULL_CHECKED, no_bucket, WARNING, [Parameter `block` of Blocks_as_parameters.blockCheckedAssignNULLBad:and:,Checking `block` for nil,Assigned,Executing `block`], "block("=>"BLOCK_CALL_SAFE(block"@88:5
codetoanalyze/objc/parameter-not-null-checked/Blocks_as_parameters.m, objc_block_Blocks_as_parameters.m:121, 1, BLOCK_PARAMETER_NOT_NULL_CHECKED, no_bucket, WARNING, [Parameter `completion` of Blocks_as_parameters.uploadTaskWithRequestBad:fromFile:delegate:delegateQueue:completion:,Executing `completion`], "completion("=>"BLOCK_CALL_SAFE(completion"@122:5
codetoanalyze/objc/parameter-not-null-checked/Blocks_as_parameters.m, objc_block_Blocks_as_parameters.m:213, 1, BLOCK_PARAMETER_NOT_NULL_CHECKED, no_bucket, WARNING, [Parameter `annotate` of objc_block_Blocks_as_parameters.m:213,Executing `annotate`], "annotate("=>"BLOCK_CALL_SAFE(annotate, "@214:5
codetoanalyze/objc/parameter-not-null-checked/Blocks_as_parameters.m, blockNotCheckedBadNoAutofix, 0, BLOCK_PARAMETER_NOT_NULL_CHECKED, no_bucket, WARNING, [Parameter `block` of blockNotCheckedBadNoAutofix,Executing `block`]

0 comments on commit 530e0b8

Please sign in to comment.