You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
690 B
40 lines
690 B
6 years ago
|
/*
|
||
6 years ago
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||
6 years ago
|
*
|
||
|
* This source code is licensed under the MIT license found in the
|
||
|
* LICENSE file in the root directory of this source tree.
|
||
|
*/
|
||
|
#include <stdlib.h>
|
||
|
|
||
|
void (*global)(void**);
|
||
|
|
||
|
struct T {
|
||
|
void (*go)();
|
||
|
};
|
||
|
|
||
|
struct S {
|
||
|
struct T* t;
|
||
|
void* x;
|
||
|
};
|
||
|
|
||
5 years ago
|
void call_global_fun_ptr_ok(void** x) {
|
||
6 years ago
|
if (global != 0) {
|
||
|
global(x);
|
||
|
}
|
||
|
}
|
||
|
|
||
5 years ago
|
void test_null_then_deref_ok(struct S* s) {
|
||
6 years ago
|
if (s == 0)
|
||
|
return;
|
||
5 years ago
|
call_global_fun_ptr_ok(&s->x);
|
||
6 years ago
|
if (s->t->go) { // should *not* give NULL_TEST_AFTER_DEREFERENCE
|
||
|
s->t->go();
|
||
|
}
|
||
|
}
|
||
|
|
||
5 years ago
|
void deref_after_null_check_bad(int* x) {
|
||
6 years ago
|
if (x == 0) {
|
||
|
*x = 1; // should give NULL_DEREFERENCE
|
||
|
}
|
||
|
}
|