diff --git a/infer/src/checkers/uninitDomain.ml b/infer/src/checkers/uninitDomain.ml index 0bb652941..bb5679467 100644 --- a/infer/src/checkers/uninitDomain.ml +++ b/infer/src/checkers/uninitDomain.ml @@ -62,12 +62,15 @@ module MaybeUninitVars = struct | _ -> maybe_uninit_vars in - match base with - | _, {Typ.desc= Tptr ({Typ.desc= Tvoid}, _)} -> - Option.value_map ~default:maybe_uninit_vars ~f:remove_all_fields_inner - (find_access_expr_typ tenv (HilExp.AccessExpression.base base) locals) - | _, typ -> - remove_all_fields_inner typ + let typ_of_arg_in_locals = + match base with + | _, {Typ.desc= Tptr _} -> + find_access_expr_typ tenv (HilExp.AccessExpression.base base) locals + | _ -> + None + in + let typ_to_remove = Option.value ~default:(snd base) typ_of_arg_in_locals in + remove_all_fields_inner typ_to_remove let remove_dereference_access base maybe_uninit_vars = diff --git a/infer/tests/codetoanalyze/cpp/uninit/uninit.cpp b/infer/tests/codetoanalyze/cpp/uninit/uninit.cpp index b7803c065..2e11e9f85 100644 --- a/infer/tests/codetoanalyze/cpp/uninit/uninit.cpp +++ b/infer/tests/codetoanalyze/cpp/uninit/uninit.cpp @@ -276,6 +276,15 @@ int* pointer_param_void_star_ok() { return a.ptr; } +void another_f(char* p); + +int* pointer_param_char_star_ok() { + A a; + int* res; + another_f((char*)&a); + return a.ptr; +} + short union_ok() { union { int* a;