Skip to content

Commit 905f3fa

Browse files
dulmarodfacebook-github-bot
authored andcommitted
[tests] [2/n] Adapt a test about treating nil messaging in Objective-C and move it to Pulse
Summary: Adapted this test to compile with ARC and to be more clear. It tests that we handle correctly the fact that messaging nil in Objective-C returns nil. Copied it to Pulse and removed it from biabduction since it doesn't work as expected in biabduction. Reviewed By: skcho Differential Revision: D32430172 fbshipit-source-id: 80b786cc3
1 parent c9e4024 commit 905f3fa

File tree

4 files changed

+34
-35
lines changed

4 files changed

+34
-35
lines changed

infer/tests/codetoanalyze/objc/biabduction/Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ SOURCES_DEFAULT = \
4646

4747
SOURCES_BUCKET_ALL = \
4848
global_const/global_const.m \
49-
npe/nil_param.m \
5049
npe/null_returned_by_method.m \
5150
procdescs/main.c \
5251
property/main.c \

infer/tests/codetoanalyze/objc/biabduction/npe/nil_param.m

Lines changed: 0 additions & 34 deletions
This file was deleted.

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ codetoanalyze/objc/pulse/null_deref/NPENilInsertionIntoCollection.m, testNilMess
4545
codetoanalyze/objc/pulse/null_deref/NPENilInsertionIntoCollection.m, testNilMessagingForModelNotNilDictBad, 1, NIL_INSERTION_INTO_COLLECTION, no_bucket, ERROR, [is the null pointer,when calling `addObjectInDict` here,parameter `value` of addObjectInDict,in call to `NSMutableDictionary.setObject:forKey:` (modelled),invalid access occurs here]
4646
codetoanalyze/objc/pulse/null_deref/SpecWithBlocksProcnameExample.m, SpecWithBlocksProcnameExample.nilBlockCallBadLatent:, 2, NIL_BLOCK_CALL_LATENT, no_bucket, ERROR, [is the null pointer,when calling `ContentSource.matchLocal:external:[specialized with blocks]` here,parameter `externalMatchHandler` of ContentSource.matchLocal:external:[specialized with blocks],invalid access occurs here]
4747
codetoanalyze/objc/pulse/null_deref/dynamic_dispatch.m, DynamicDispatchMain.no_dynamic_dispatch_npe_bad, 2, NULLPTR_DEREFERENCE, no_bucket, ERROR, [in call to `DynamicDispatchMain.get_ddclass_from_instance:`,in call to `PInstance.get_ddclass`,is the null pointer,returned,return from call to `PInstance.get_ddclass`,returned,return from call to `DynamicDispatchMain.get_ddclass_from_instance:`,invalid access occurs here]
48+
codetoanalyze/objc/pulse/null_deref/nil_param.m, NilParamNpeBad, 2, NULLPTR_DEREFERENCE, no_bucket, ERROR, [is the null pointer,in call to `NilParamA.test:`,parameter `other` of NilParamA.test:,in call to `NilParamA.newObject`,parameter `self` of NilParamA.newObject,a message sent to nil returns nil,return from call to `NilParamA.newObject`,returned,return from call to `NilParamA.test:`,invalid access occurs here]
4849
codetoanalyze/objc/pulse/uninit.m, Uninit.call_setter_c_struct_bad, 3, PULSE_UNINITIALIZED_VALUE, no_bucket, ERROR, [struct field address `x` created,when calling `Uninit.setS:` here,parameter `s` of Uninit.setS:,read to uninitialized value occurs here]
4950
codetoanalyze/objc/pulse/use_after_free.m, PulseTest.use_after_free_simple_in_objc_method_bad:, 2, USE_AFTER_FREE, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `x` of PulseTest.use_after_free_simple_in_objc_method_bad:,was invalidated by call to `free()`,use-after-lifetime part of the trace starts here,parameter `x` of PulseTest.use_after_free_simple_in_objc_method_bad:,invalid access occurs here]
5051
codetoanalyze/objc/pulse/use_after_free.m, use_after_free_simple_bad, 2, USE_AFTER_FREE, no_bucket, ERROR, [invalidation part of the trace starts here,parameter `x` of use_after_free_simple_bad,was invalidated by call to `free()`,use-after-lifetime part of the trace starts here,parameter `x` of use_after_free_simple_bad,invalid access occurs here]
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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/NSObject.h>
9+
10+
@interface NilParamA : NSObject {
11+
@public
12+
int x;
13+
}
14+
@end
15+
16+
@implementation NilParamA
17+
18+
- (NilParamA*)newObject {
19+
return [[NilParamA alloc] init];
20+
}
21+
22+
- (NilParamA*)test:(NilParamA*)other {
23+
return [other newObject];
24+
}
25+
26+
@end
27+
28+
// This test shows that when we call an Objective-C method with nil we don't
29+
// call the method but we return nil instead.
30+
int NilParamNpeBad() {
31+
NilParamA* a = [[NilParamA alloc] init];
32+
return [a test:nil]->x;
33+
}

0 commit comments

Comments
 (0)