From 5679105c15ef33d846850af381f2e941ad2a7226 Mon Sep 17 00:00:00 2001 From: Mehdi Bouaziz Date: Tue, 9 Oct 2018 02:44:19 -0700 Subject: [PATCH] [Uninit][7/13] Add new tests Reviewed By: jeremydubreil Differential Revision: D10250168 fbshipit-source-id: 5e5983f04 --- infer/tests/codetoanalyze/c/uninit/uninit.c | 5 +++ .../tests/codetoanalyze/cpp/uninit/issues.exp | 1 + .../tests/codetoanalyze/cpp/uninit/struct.cpp | 10 +++++ .../tests/codetoanalyze/cpp/uninit/uninit.cpp | 37 +++++++++++++++++++ 4 files changed, 53 insertions(+) diff --git a/infer/tests/codetoanalyze/c/uninit/uninit.c b/infer/tests/codetoanalyze/c/uninit/uninit.c index 8433cdebe..839f1e997 100644 --- a/infer/tests/codetoanalyze/c/uninit/uninit.c +++ b/infer/tests/codetoanalyze/c/uninit/uninit.c @@ -20,3 +20,8 @@ int dereference_bad() { int* p; return *p; } + +void FN_self_assign() { + int x; + x = x; +} diff --git a/infer/tests/codetoanalyze/cpp/uninit/issues.exp b/infer/tests/codetoanalyze/cpp/uninit/issues.exp index f3a1a9743..15110f6f1 100644 --- a/infer/tests/codetoanalyze/cpp/uninit/issues.exp +++ b/infer/tests/codetoanalyze/cpp/uninit/issues.exp @@ -8,6 +8,7 @@ codetoanalyze/cpp/uninit/members.cpp, access_pointer_members_bad, 3, UNINITIALIZ codetoanalyze/cpp/uninit/members.cpp, access_pointer_members_bad, 4, UNINITIALIZED_VALUE, no_bucket, ERROR, [] codetoanalyze/cpp/uninit/members.cpp, access_pointer_members_bad, 5, UNINITIALIZED_VALUE, no_bucket, ERROR, [] codetoanalyze/cpp/uninit/struct.cpp, pass_basic_type_field_bad, 3, UNINITIALIZED_VALUE, no_bucket, ERROR, [] +codetoanalyze/cpp/uninit/struct.cpp, struct_partial_init_bad, 6, UNINITIALIZED_VALUE, no_bucket, ERROR, [] codetoanalyze/cpp/uninit/struct.cpp, struct_uninit_bad, 3, UNINITIALIZED_VALUE, no_bucket, ERROR, [] codetoanalyze/cpp/uninit/uninit.cpp, FP_no_warning_noreturn_callee_ok, 7, UNINITIALIZED_VALUE, no_bucket, ERROR, [] codetoanalyze/cpp/uninit/uninit.cpp, FP_pointer_param_void_star_ok, 4, UNINITIALIZED_VALUE, no_bucket, ERROR, [] diff --git a/infer/tests/codetoanalyze/cpp/uninit/struct.cpp b/infer/tests/codetoanalyze/cpp/uninit/struct.cpp index 96450f086..b7b70526b 100644 --- a/infer/tests/codetoanalyze/cpp/uninit/struct.cpp +++ b/infer/tests/codetoanalyze/cpp/uninit/struct.cpp @@ -149,3 +149,13 @@ int foo() { struct s t = not_a_constructor_but_returning_T(); return t.n; } + +short struct_partial_init_bad() { + struct { + int* a; + short* b; + } s; + s.a = 0; + short* p = s.b; + return *p; +} diff --git a/infer/tests/codetoanalyze/cpp/uninit/uninit.cpp b/infer/tests/codetoanalyze/cpp/uninit/uninit.cpp index 6d0b5ba50..df91ce994 100644 --- a/infer/tests/codetoanalyze/cpp/uninit/uninit.cpp +++ b/infer/tests/codetoanalyze/cpp/uninit/uninit.cpp @@ -293,3 +293,40 @@ int condition_no_init_bad() { } return 0; } + +void call_to_fn_ptr_with_init_arg_good(void (*f)(int)) { + int a = 42; + f(a); +} + +void FN_call_to_fn_ptr_with_uninit_arg_bad(void (*f)(int)) { + int a; + f(a); +} + +void call_to_init_fn_ptr_good() { + void (*f)(); + f = use_square_ok1; + f(); +} + +void call_to_init_fn_ptr2_good(bool nondet) { + void (*f)(); + if (nondet) + f = use_square_ok1; + else + f = deref_magic_addr_ok; + f(); +} + +void FN_call_to_uninit_fn_ptr_bad() { + void (*f)(); + f(); +} + +void FN_call_to_maybe_uninit_fn_ptr_bad(bool nondet) { + void (*f)(); + if (nondet) + f = use_square_ok1; + f(); +}