[uninit] Enable reporting on uninitialized pointers

Reviewed By: jeremydubreil

Differential Revision: D6567381

fbshipit-source-id: c35f6e3
master
Daiva Naudziuniene 7 years ago committed by Facebook Github Bot
parent 4927e31c2f
commit d7d3e16d6f

@ -28,12 +28,12 @@ end)
let blacklisted_functions = [BuiltinDecl.__set_array_length] let blacklisted_functions = [BuiltinDecl.__set_array_length]
let rec is_basic_type t = let should_report_on_type t =
match t.Typ.desc with match t.Typ.desc with
| Tint _ | Tfloat _ | Tvoid -> | Tptr (_, Pk_reference) ->
false
| Tint _ | Tfloat _ | Tvoid | Tptr _ ->
true true
| Tptr (t', _) ->
is_basic_type t'
| _ -> | _ ->
false false
@ -76,7 +76,7 @@ module TransferFunctions (CFG : ProcCfg.S) = struct
match (AccessExpression.get_typ access_expr tenv, base) with match (AccessExpression.get_typ access_expr tenv, base) with
| Some typ, (Var.ProgramVar pv, _) -> | Some typ, (Var.ProgramVar pv, _) ->
not (Pvar.is_frontend_tmp pv) && not (Procdesc.is_captured_var pdesc pv) not (Pvar.is_frontend_tmp pv) && not (Procdesc.is_captured_var pdesc pv)
&& D.mem access_expr uninit_vars && is_basic_type typ && D.mem access_expr uninit_vars && should_report_on_type typ
| _, _ -> | _, _ ->
false false
@ -271,7 +271,7 @@ module TransferFunctions (CFG : ProcCfg.S) = struct
| None -> | None ->
false false
| Some lhs_ap_typ -> | Some lhs_ap_typ ->
not (Typ.is_pointer lhs_ap_typ) not (Typ.is_reference lhs_ap_typ)
in in
( match rhs_expr with ( match rhs_expr with
| AccessExpression rhs_access_expr -> | AccessExpression rhs_access_expr ->

@ -3,12 +3,18 @@ codetoanalyze/cpp/uninit/default_constr.cpp, init_bad, 3, UNINITIALIZED_VALUE, E
codetoanalyze/cpp/uninit/members.cpp, access_members_bad, 4, UNINITIALIZED_VALUE, ERROR, [] codetoanalyze/cpp/uninit/members.cpp, access_members_bad, 4, UNINITIALIZED_VALUE, ERROR, []
codetoanalyze/cpp/uninit/members.cpp, access_members_bad2, 4, UNINITIALIZED_VALUE, ERROR, [] codetoanalyze/cpp/uninit/members.cpp, access_members_bad2, 4, UNINITIALIZED_VALUE, ERROR, []
codetoanalyze/cpp/uninit/members.cpp, access_members_bad3, 4, UNINITIALIZED_VALUE, ERROR, [] codetoanalyze/cpp/uninit/members.cpp, access_members_bad3, 4, UNINITIALIZED_VALUE, ERROR, []
codetoanalyze/cpp/uninit/members.cpp, access_pointer_members_bad, 3, UNINITIALIZED_VALUE, ERROR, []
codetoanalyze/cpp/uninit/members.cpp, access_pointer_members_bad, 4, UNINITIALIZED_VALUE, ERROR, []
codetoanalyze/cpp/uninit/members.cpp, access_pointer_members_bad, 5, UNINITIALIZED_VALUE, ERROR, []
codetoanalyze/cpp/uninit/struct.cpp, pass_basic_type_field_bad, 3, UNINITIALIZED_VALUE, ERROR, [] codetoanalyze/cpp/uninit/struct.cpp, pass_basic_type_field_bad, 3, UNINITIALIZED_VALUE, ERROR, []
codetoanalyze/cpp/uninit/struct.cpp, struct_uninit_bad, 3, UNINITIALIZED_VALUE, ERROR, [] codetoanalyze/cpp/uninit/struct.cpp, struct_uninit_bad, 3, UNINITIALIZED_VALUE, ERROR, []
codetoanalyze/cpp/uninit/uninit.cpp, FP_no_warning_noreturn_callee_ok, 7, UNINITIALIZED_VALUE, ERROR, [] codetoanalyze/cpp/uninit/uninit.cpp, FP_no_warning_noreturn_callee_ok, 7, UNINITIALIZED_VALUE, ERROR, []
codetoanalyze/cpp/uninit/uninit.cpp, FP_pointer_param_void_star_ok, 4, UNINITIALIZED_VALUE, ERROR, []
codetoanalyze/cpp/uninit/uninit.cpp, FP_union_ok, 6, UNINITIALIZED_VALUE, ERROR, []
codetoanalyze/cpp/uninit/uninit.cpp, bad1, 2, UNINITIALIZED_VALUE, ERROR, [] codetoanalyze/cpp/uninit/uninit.cpp, bad1, 2, UNINITIALIZED_VALUE, ERROR, []
codetoanalyze/cpp/uninit/uninit.cpp, bad2, 2, UNINITIALIZED_VALUE, ERROR, [] codetoanalyze/cpp/uninit/uninit.cpp, bad2, 2, UNINITIALIZED_VALUE, ERROR, []
codetoanalyze/cpp/uninit/uninit.cpp, branch1_FP, 11, UNINITIALIZED_VALUE, ERROR, [] codetoanalyze/cpp/uninit/uninit.cpp, branch1_FP, 11, UNINITIALIZED_VALUE, ERROR, []
codetoanalyze/cpp/uninit/uninit.cpp, copy_pointer_bad, 3, UNINITIALIZED_VALUE, ERROR, []
codetoanalyze/cpp/uninit/uninit.cpp, loop1_FP, 10, UNINITIALIZED_VALUE, ERROR, [] codetoanalyze/cpp/uninit/uninit.cpp, loop1_FP, 10, UNINITIALIZED_VALUE, ERROR, []
codetoanalyze/cpp/uninit/uninit.cpp, no_init_return_bad, 2, UNINITIALIZED_VALUE, ERROR, [] codetoanalyze/cpp/uninit/uninit.cpp, no_init_return_bad, 2, UNINITIALIZED_VALUE, ERROR, []
codetoanalyze/cpp/uninit/uninit.cpp, ret_undef_bad, 2, UNINITIALIZED_VALUE, ERROR, [] codetoanalyze/cpp/uninit/uninit.cpp, ret_undef_bad, 2, UNINITIALIZED_VALUE, ERROR, []

@ -11,7 +11,9 @@
class A { class A {
public: public:
int* ptr;
std::string a_name; std::string a_name;
std::string* p_a_name;
int i; int i;
A() {} // user defined default constructor. A() {} // user defined default constructor.
@ -63,3 +65,13 @@ int access_members_bad3() {
return 0; return 0;
}; };
int access_pointer_members_bad() {
A a;
int* p = a.ptr;
int i = a.i;
std::string* pn = a.p_a_name;
return 0;
};

@ -181,11 +181,11 @@ int ret_undef_bad() {
return *p; // report as p was not initialized return *p; // report as p was not initialized
} }
int ret_undef_FP() { int copy_pointer_bad() {
int* p; int* p;
int* q; int* q;
p = q; // no report as we copy an address p = q; // error
return *p; // NO report as we don't keep track of aliasing (for now) return *p;
} }
void use_an_int2(int*); void use_an_int2(int*);
@ -263,3 +263,22 @@ int FP_no_warning_noreturn_callee_ok(bool t) {
} }
return x; return x;
} }
void some_f(void* p);
int* FP_pointer_param_void_star_ok() {
A a;
int* res;
some_f(&a); // the type of a here is void*, hence no fields are found
return a.ptr; // false positive
}
short FP_union_ok() {
union {
int* a;
short* b;
} u;
init(u.a);
short* p = u.b; // false positive
return *p;
}

@ -1,4 +1,5 @@
codetoanalyze/objc/uninit/arrays.m, array_length_undef_bad, 2, UNINITIALIZED_VALUE, ERROR, [] codetoanalyze/objc/uninit/arrays.m, array_length_undef_bad, 2, UNINITIALIZED_VALUE, ERROR, []
codetoanalyze/objc/uninit/arrays.m, bad1, 3, UNINITIALIZED_VALUE, ERROR, [] codetoanalyze/objc/uninit/arrays.m, bad1, 3, UNINITIALIZED_VALUE, ERROR, []
codetoanalyze/objc/uninit/arrays.m, bad2, 2, UNINITIALIZED_VALUE, ERROR, [] codetoanalyze/objc/uninit/arrays.m, bad2, 2, UNINITIALIZED_VALUE, ERROR, []
codetoanalyze/objc/uninit/uninit.m, FP_switch_ok, 11, UNINITIALIZED_VALUE, ERROR, []
codetoanalyze/objc/uninit/uninit_blocks.m, A_bad1, 5, UNINITIALIZED_VALUE, ERROR, [] codetoanalyze/objc/uninit/uninit_blocks.m, A_bad1, 5, UNINITIALIZED_VALUE, ERROR, []

@ -30,4 +30,20 @@
return labelSize.height; // Here we should not report uninit return labelSize.height; // Here we should not report uninit
} }
typedef NS_ENUM(NSUInteger, SomeEnum) { ValueA, ValueB };
CGColorRef FP_switch_ok(SomeEnum e, CGColorRef defaultcolor) {
CGColorRef color;
switch (e) {
case ValueA:
color = defaultcolor;
break;
case ValueB:
color = defaultcolor;
break;
}
return color; // false positive because of exausted switch
}
@end @end

Loading…
Cancel
Save