diff --git a/infer/src/biabduction/SymExecBlocks.ml b/infer/src/biabduction/SymExecBlocks.ml index 4ed8ddbbd..25da5c64d 100644 --- a/infer/src/biabduction/SymExecBlocks.ml +++ b/infer/src/biabduction/SymExecBlocks.ml @@ -38,7 +38,7 @@ let get_extended_args_for_method_with_block_analysis act_params = in append_no_duplicates_vars all_args captured | _ -> - append_no_duplicates_vars all_args [act_param] ) + List.append all_args [act_param] ) in List.map ~f:(fun (exp, _, typ) -> (exp, typ)) args_and_captured diff --git a/infer/tests/codetoanalyze/objc/errors/Makefile b/infer/tests/codetoanalyze/objc/errors/Makefile index 9276073ea..68a37bddd 100644 --- a/infer/tests/codetoanalyze/objc/errors/Makefile +++ b/infer/tests/codetoanalyze/objc/errors/Makefile @@ -74,6 +74,7 @@ SOURCES_BUCKET_ALL = \ returnstmt/return_npe_test.m \ shared/assertions/NSAssert_example.m \ shared/block/BlockVar.m \ + shared/block/AnonymousBlock.m \ shared/block/block.m \ shared/block/block_no_args.m \ shared/block/block_release.m \ diff --git a/infer/tests/codetoanalyze/objc/shared/block/AnonymousBlock.m b/infer/tests/codetoanalyze/objc/shared/block/AnonymousBlock.m new file mode 100644 index 000000000..7463734bf --- /dev/null +++ b/infer/tests/codetoanalyze/objc/shared/block/AnonymousBlock.m @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2018-present, Facebook, Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +#import + +void anonBlock() { + CFRunLoopObserverRef observer = CFRunLoopObserverCreateWithHandler( + NULL, + kCFRunLoopBeforeWaiting, + NO, + UINT_MAX, + ^(CFRunLoopObserverRef obs, CFRunLoopActivity activity) { + CFRelease(obs); + }); + CFRunLoopAddObserver(CFRunLoopGetMain(), observer, kCFRunLoopCommonModes); +} + +void blockVar() { + // This case doesnt fail like the one above (with the anonymous block) used + // to. That's because using the block variable populates the args list + // differently thus avoiding the dupliate. + void (^bvar)(CFRunLoopObserverRef observer, CFRunLoopActivity activity) = + ^(CFRunLoopObserverRef obs, CFRunLoopActivity activity) { + CFRelease(obs); + }; + + CFRunLoopObserverRef observer = CFRunLoopObserverCreateWithHandler( + NULL, kCFRunLoopBeforeWaiting, NO, UINT_MAX, bvar); + CFRunLoopAddObserver(CFRunLoopGetMain(), observer, kCFRunLoopCommonModes); +}