From 5898417fddbf2b1386eab665d2a7a177d8073f4d Mon Sep 17 00:00:00 2001 From: Daiva Naudziuniene Date: Fri, 9 Mar 2018 07:53:58 -0800 Subject: [PATCH] [frontend] Getting appropriate type information for exp in sizeof exp Summary: : Previously, we did not have information about type of `exp` in `sizeof exp` from clang plugin which led to `Bad_footprint` errors. Infer did not understand `sizeof *p` in `struct Person* p = malloc(sizeof *p);` and used some default type. This resulted in `Bad_footprint` error when trying to assign to a field `age` in `p->age=42;`. This diff uses the version of clang plugin which exports the appropriate type information. update-submodule: facebook-clang-plugins Reviewed By: dulmarod Differential Revision: D7179870 fbshipit-source-id: 4104f10 --- facebook-clang-plugins | 2 +- .../c/errors/null_dereference/null_pointer_dereference.c | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/facebook-clang-plugins b/facebook-clang-plugins index 9d03cb460..a77526452 160000 --- a/facebook-clang-plugins +++ b/facebook-clang-plugins @@ -1 +1 @@ -Subproject commit 9d03cb460a30ad02d7b5edfa38f3a1143e642cfe +Subproject commit a77526452b10339b3580d58b02c9c8f534b79589 diff --git a/infer/tests/codetoanalyze/c/errors/null_dereference/null_pointer_dereference.c b/infer/tests/codetoanalyze/c/errors/null_dereference/null_pointer_dereference.c index ae03284a8..55678369f 100644 --- a/infer/tests/codetoanalyze/c/errors/null_dereference/null_pointer_dereference.c +++ b/infer/tests/codetoanalyze/c/errors/null_dereference/null_pointer_dereference.c @@ -129,3 +129,11 @@ void function_call_returns_allocated_pointer() { assign(p, 42); free(p); } + +void sizeof_expr_ok(void) { + struct Person* p = malloc(sizeof *p); + if (p) { + p->age = 42; + } + free(p); +}