Skip to content

Commit ec5841c

Browse files
dulmarodfacebook-github-bot
authored andcommitted
[tests] [6/n] Add tests about nullable annotation to Pulse
Summary: Copied over from biabduction a test about reporting an error when parameters annotated with nullable are dereferenced. This is not currently implemented in Pulse. Reviewed By: skcho Differential Revision: D32433126 fbshipit-source-id: b97eb8a86
1 parent d934040 commit ec5841c

File tree

1 file changed

+70
-0
lines changed
  • infer/tests/codetoanalyze/objc/pulse/null_deref

1 file changed

+70
-0
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
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+
8+
#import <Foundation/NSString.h>
9+
10+
@interface NullableA : NSObject {
11+
@public
12+
int fld;
13+
}
14+
15+
@end
16+
17+
@interface NullableB : NSObject
18+
19+
@property int prop;
20+
21+
- (void)method;
22+
23+
@end
24+
25+
/*
26+
This test is about reporting an error when parameters annotated with nullable
27+
are dereferenced. This is not currently implemented in Pulse.
28+
*/
29+
30+
int derefNullableParamDirectBad_FN(NullableA* __nullable param) {
31+
return param->fld;
32+
}
33+
34+
int derefNullableParamIndirectBad_FN(NullableA* __nullable param) {
35+
NullableA* local = param;
36+
return local->fld;
37+
}
38+
39+
NullableA* derefNullableParamOk(NullableA* __nullable param) {
40+
if (!param)
41+
param = [NullableA new];
42+
param->fld = 7;
43+
return param;
44+
}
45+
46+
int parameter_nullable_ok(NSString* body,
47+
NSString* __nullable linkTapAction,
48+
NullableA* options) {
49+
return options->fld;
50+
}
51+
52+
int parameter_nullable_bad_FN(NullableA* __nullable options,
53+
NSAttributedString* body,
54+
NSString* linkTapAction)
55+
56+
{
57+
return options->fld;
58+
}
59+
60+
int readNullableParamPropertyOk(NullableB* __nullable param) {
61+
return param.prop;
62+
}
63+
64+
void writeNullableParamPropertyOk(NullableB* __nullable param) {
65+
param.prop = 7;
66+
}
67+
68+
void methodCallOnNullableParamOk(NullableB* __nullable param) {
69+
[param method];
70+
}

0 commit comments

Comments
 (0)