Skip to content

Commit 0c871de

Browse files
dulmarodfacebook-github-bot
authored andcommitted
[tests] [2/n] Add test about method specialized with block to Pulse
Summary: Added a test to Pulse of NPE that is found after correctly specialising a method with a block. Reviewed By: jvillard Differential Revision: D32533341 fbshipit-source-id: 3c0d42890
1 parent d939eb5 commit 0c871de

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

infer/tests/codetoanalyze/objc/pulse/issues.exp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ codetoanalyze/objc/pulse/memory_leaks/MemoryLeaks.m, call_bridge_interproc_leak_
88
codetoanalyze/objc/pulse/memory_leaks/MemoryLeaks.m, call_cfrelease_interproc_leak_ok_FP, 2, MEMORY_LEAK, no_bucket, ERROR, [allocation part of the trace starts here,allocated by `CFLocaleCreate (custom malloc)` here,memory becomes unreachable here]
99
codetoanalyze/objc/pulse/memory_leaks/MemoryLeaksInBlocks.m, block_captured_var_leak_bad, 6, MEMORY_LEAK, no_bucket, ERROR, [allocation part of the trace starts here,allocated by `malloc` here,memory becomes unreachable here]
1010
codetoanalyze/objc/pulse/memory_leaks/MemoryLeaksInBlocks.m, objc_blockblock_free_ok_npe_latent_FP_2, 1, NULLPTR_DEREFERENCE_LATENT, no_bucket, ERROR, [source of the null value part of the trace starts here,is the null pointer,null pointer dereference part of the trace starts here,parameter `x` of objc_blockblock_free_ok_npe_latent_FP_2,invalid access occurs here]
11+
codetoanalyze/objc/pulse/null_deref/Blocks_as_parameter.m, call_f_npe_bad, 6, NULLPTR_DEREFERENCE, no_bucket, ERROR, [in call to `B.f`,parameter `self` of B.f,in call to `B.call_block:[specialized with blocks]`,in call to `objc_blockB.f_1`,is the constant 5,assigned,return from call to `objc_blockB.f_1`,return from call to `B.call_block:[specialized with blocks]`,returned,return from call to `B.f`,assigned,taking "then" branch,is the null pointer,assigned,invalid access occurs here]
1112
codetoanalyze/objc/pulse/null_deref/FrontendEqualNames.m, EqualNamesInstanceNPEBad, 3, NULLPTR_DEREFERENCE, no_bucket, ERROR, [in call to `EqualNamesA.meth`,is the null pointer,returned,return from call to `EqualNamesA.meth`,assigned,invalid access occurs here]
1213
codetoanalyze/objc/pulse/null_deref/FrontendExplicitIvarName.m, ExplicitIvarNameA.testDefaultName, 7, NULLPTR_DEREFERENCE, no_bucket, ERROR, [is the null pointer,assigned,invalid access occurs here]
1314
codetoanalyze/objc/pulse/null_deref/FrontendExplicitIvarName.m, ExplicitIvarNameA.testExplicit, 6, NULLPTR_DEREFERENCE, no_bucket, ERROR, [is the null pointer,assigned,invalid access occurs here]
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
#import <Foundation/NSObject.h>
8+
9+
typedef void (^MyBlock)();
10+
11+
@interface B : NSObject {
12+
int y;
13+
int x;
14+
}
15+
- (void)call_block:(MyBlock)block;
16+
17+
@end
18+
19+
@implementation B
20+
21+
- (void)call_block:(MyBlock)block {
22+
block();
23+
}
24+
25+
- (int)f {
26+
[self call_block:^{
27+
self->x = 5;
28+
}];
29+
return self->x + self->y;
30+
}
31+
32+
void call_f_npe_bad() {
33+
B* b = [[B alloc] init];
34+
b->y = 10;
35+
int z = [b f];
36+
if (z == 15) {
37+
int* p = NULL;
38+
*p = 42;
39+
}
40+
}
41+
42+
void call_f_no_npe_good() {
43+
B* b = [[B alloc] init];
44+
b->y = 10;
45+
int z = [b f];
46+
if (z == 1) {
47+
int* p = NULL;
48+
*p = 42;
49+
}
50+
}
51+
@end

0 commit comments

Comments
 (0)