Summary: Note: Disabled by default. Having some support for values, we can report when a null or constant value is being dereferenced. The particularity here is that we don't report when 0 is a possible value for the address, or even if we know that the value of the address can only be 0 in that branch! Instead, we allow ourselves to report only when we the address has been *set* to NULL (or any constant). This is in line with how pulse deals with other issues: only report when 1. we see an address become invalid, and 2. we see the same address be used later on Reviewed By: skcho Differential Revision: D17665468 fbshipit-source-id: f1ccf94cfmaster
parent
a107b2dd2d
commit
6df4fb6a9b
@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
void assign_zero_ok() {
|
||||
int x[2];
|
||||
x[1] = 42;
|
||||
}
|
||||
|
||||
void deref_nullptr_bad() {
|
||||
int* p = nullptr;
|
||||
*p = 42;
|
||||
}
|
||||
|
||||
void guarded_nullptr_ok() {
|
||||
int* p = nullptr;
|
||||
if (p != nullptr) {
|
||||
*p = 42;
|
||||
}
|
||||
}
|
||||
|
||||
struct X {
|
||||
void foo();
|
||||
};
|
||||
|
||||
bool choice();
|
||||
|
||||
X* may_return_nullptr() {
|
||||
if (choice) {
|
||||
return nullptr;
|
||||
}
|
||||
return new X();
|
||||
}
|
||||
|
||||
void no_check_return_bad() {
|
||||
X* x = may_return_nullptr();
|
||||
x->foo();
|
||||
}
|
||||
|
||||
void check_return_ok() {
|
||||
X* x = may_return_nullptr();
|
||||
if (x != nullptr) {
|
||||
x->foo();
|
||||
}
|
||||
}
|
||||
|
||||
void compare_to_null(void* x) {
|
||||
if (x) {
|
||||
}
|
||||
}
|
||||
|
||||
void deref_after_compare_ok(int* x) {
|
||||
compare_to_null(x);
|
||||
*x = 42;
|
||||
}
|
Loading…
Reference in new issue