Summary: Example of combination between annotating fields with nullable and the biabduction analysis in Objective C Reviewed By: dulmarod Differential Revision: D5906016 fbshipit-source-id: b95c6e0master
parent
9f9dbdb914
commit
14d01620d2
@ -0,0 +1,19 @@
|
||||
# Copyright (c) 2017 - present Facebook, Inc.
|
||||
# All rights reserved.
|
||||
#
|
||||
# This source code is licensed under the BSD style license found in the
|
||||
# LICENSE file in the root directory of this source tree. An additional grant
|
||||
# of patent rights can be found in the PATENTS file in the same directory.
|
||||
|
||||
TESTS_DIR = ../../..
|
||||
|
||||
ANALYZER = checkers
|
||||
CLANG_OPTIONS = -c
|
||||
INFER_OPTIONS = --biabduction --suggest-nullable --debug-exceptions --project-root $(TESTS_DIR)
|
||||
INFERPRINT_OPTIONS = --issues-tests
|
||||
|
||||
SOURCES = $(wildcard *.m)
|
||||
|
||||
include $(TESTS_DIR)/clang.make
|
||||
|
||||
infer-out/report.json: $(MAKEFILE_LIST)
|
@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Copyright (c) 2017 - present Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
#import <Foundation/NSString.h>
|
||||
|
||||
@interface T : NSObject
|
||||
- (void)assignUnnanotatedFieldToNullBad;
|
||||
@end
|
||||
|
||||
@implementation T {
|
||||
int* unnanotatedField;
|
||||
int* __nullable nullableField;
|
||||
int* nonnullField;
|
||||
}
|
||||
|
||||
- (void)assignNullableFieldToNullOkay {
|
||||
nullableField = nil;
|
||||
}
|
||||
|
||||
- (void)assignUnnanotatedFieldToNullBad {
|
||||
unnanotatedField = nil;
|
||||
}
|
||||
|
||||
- (void)assignNonnullFieldToNullBad {
|
||||
nonnullField = nil;
|
||||
}
|
||||
|
||||
- (void)testNullableFieldForNullOkay {
|
||||
if (nullableField == nil) {
|
||||
}
|
||||
}
|
||||
|
||||
- (void)testUnnanotatedFieldForNullBad {
|
||||
if (unnanotatedField == nil) {
|
||||
}
|
||||
}
|
||||
|
||||
- (void)testNonnullFieldForNullBad {
|
||||
if (nonnullField == nil) {
|
||||
}
|
||||
}
|
||||
|
||||
- (void)dereferenceUnnanotatedFieldOkay {
|
||||
*unnanotatedField = 42;
|
||||
}
|
||||
|
||||
- (void)dereferenceNonnullFieldOkay {
|
||||
*nonnullField = 42;
|
||||
}
|
||||
|
||||
- (void)dereferenceNullableFieldBad {
|
||||
*nullableField = 42;
|
||||
}
|
||||
|
||||
- (void)dereferenceUnnanotatedFieldAfterTestForNullBad {
|
||||
if (unnanotatedField == nil) {
|
||||
*unnanotatedField = 42;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)FP_dereferenceNonnullFieldAfterTestForNullOkay {
|
||||
if (nonnullField == nil) {
|
||||
*nonnullField = 42;
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
@ -0,0 +1,9 @@
|
||||
codetoanalyze/objc/checkers/Nullable.m, T_FP_dereferenceNonnullFieldAfterTestForNullOkay, 1, FIELD_SHOULD_BE_NULLABLE, [Field nonnullField is compared to null here]
|
||||
codetoanalyze/objc/checkers/Nullable.m, T_FP_dereferenceNonnullFieldAfterTestForNullOkay, 2, NULL_DEREFERENCE, [start of procedure FP_dereferenceNonnullFieldAfterTestForNullOkay,Condition is true]
|
||||
codetoanalyze/objc/checkers/Nullable.m, T_assignNonnullFieldToNullBad, 1, FIELD_SHOULD_BE_NULLABLE, [Field nonnullField is assigned null here]
|
||||
codetoanalyze/objc/checkers/Nullable.m, T_assignUnnanotatedFieldToNullBad, 1, FIELD_SHOULD_BE_NULLABLE, [Field unnanotatedField is assigned null here]
|
||||
codetoanalyze/objc/checkers/Nullable.m, T_dereferenceNullableFieldBad, 1, NULL_DEREFERENCE, [start of procedure dereferenceNullableFieldBad]
|
||||
codetoanalyze/objc/checkers/Nullable.m, T_dereferenceUnnanotatedFieldAfterTestForNullBad, 1, FIELD_SHOULD_BE_NULLABLE, [Field unnanotatedField is compared to null here]
|
||||
codetoanalyze/objc/checkers/Nullable.m, T_dereferenceUnnanotatedFieldAfterTestForNullBad, 2, NULL_DEREFERENCE, [start of procedure dereferenceUnnanotatedFieldAfterTestForNullBad,Condition is true]
|
||||
codetoanalyze/objc/checkers/Nullable.m, T_testNonnullFieldForNullBad, 1, FIELD_SHOULD_BE_NULLABLE, [Field nonnullField is compared to null here]
|
||||
codetoanalyze/objc/checkers/Nullable.m, T_testUnnanotatedFieldForNullBad, 1, FIELD_SHOULD_BE_NULLABLE, [Field unnanotatedField is compared to null here]
|
Loading…
Reference in new issue