Summary: Suggesting to add `_Nullable` on the fields checked for, or assigned to, `nullptr` will allow the biabduction analysis to report null dereferences that are related to the lifetime of objects. Depends on D5832147 Reviewed By: sblackshear Differential Revision: D5836538 fbshipit-source-id: c1b8e48master
parent
919b9268d4
commit
4ec5440692
@ -0,0 +1,21 @@
|
|||||||
|
# Copyright (c) 2016 - 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
|
||||||
|
# see explanations in cpp/errors/Makefile for the custom isystem
|
||||||
|
CLANG_OPTIONS = -x c++ -std=c++11 -nostdinc++ -isystem$(ROOT_DIR) -isystem$(CLANG_INCLUDES)/c++/v1/ -c
|
||||||
|
INFER_OPTIONS = --biabduction --suggest-nullable --debug-exceptions --project-root $(TESTS_DIR)
|
||||||
|
INFER_OPTIONS += --debug
|
||||||
|
INFERPRINT_OPTIONS = --issues-tests
|
||||||
|
|
||||||
|
SOURCES = $(wildcard *.cpp)
|
||||||
|
|
||||||
|
include $(TESTS_DIR)/clang.make
|
||||||
|
|
||||||
|
infer-out/report.json: $(MAKEFILE_LIST)
|
@ -0,0 +1,34 @@
|
|||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
class T {
|
||||||
|
private:
|
||||||
|
int* _Nullable nullable_field;
|
||||||
|
int* unnanotated_field;
|
||||||
|
|
||||||
|
public:
|
||||||
|
void assign_nullable_field_to_null_okay() { nullable_field = nullptr; }
|
||||||
|
|
||||||
|
public:
|
||||||
|
void assign_unnanotated_field_to_null_bad() { unnanotated_field = nullptr; }
|
||||||
|
|
||||||
|
public:
|
||||||
|
void test_nullable_field_for_null_okay() {
|
||||||
|
if (nullable_field == nullptr) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
void test_unnanotated_field_for_null_bad() {
|
||||||
|
if (unnanotated_field == nullptr) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
void FN_dereference_nullable_field_bad() { *nullable_field = 42; }
|
||||||
|
};
|
@ -0,0 +1,4 @@
|
|||||||
|
codetoanalyze/cpp/nullable/example.cpp, T_assign_nullable_field_to_null_okay, 0, FIELD_SHOULD_BE_NULLABLE, [Field nullable_field is assigned null here]
|
||||||
|
codetoanalyze/cpp/nullable/example.cpp, T_assign_unnanotated_field_to_null_bad, 0, FIELD_SHOULD_BE_NULLABLE, [Field unnanotated_field is assigned null here]
|
||||||
|
codetoanalyze/cpp/nullable/example.cpp, T_test_nullable_field_for_null_okay, 1, FIELD_SHOULD_BE_NULLABLE, [Field nullable_field is compared to null here]
|
||||||
|
codetoanalyze/cpp/nullable/example.cpp, T_test_unnanotated_field_for_null_bad, 1, FIELD_SHOULD_BE_NULLABLE, [Field unnanotated_field is compared to null here]
|
Loading…
Reference in new issue