From 1f5eea98b5ea0f699b9647ed9a447a6cd6a45574 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Wed, 22 Jul 2015 21:58:06 +0200 Subject: [PATCH] CheckUninitVar: Fix a FP reported for invalid code --- lib/checkuninitvar.cpp | 2 +- test/testuninitvar.cpp | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/checkuninitvar.cpp b/lib/checkuninitvar.cpp index 65b74b2ac..66c6fda58 100644 --- a/lib/checkuninitvar.cpp +++ b/lib/checkuninitvar.cpp @@ -1916,7 +1916,7 @@ int CheckUninitVar::isFunctionParUsage(const Token *vartok, bool pointer, Alloc return alloc == NO_ALLOC; } else { const bool isnullbad = _settings->library.isnullargbad(start->previous(), argumentNumber + 1); - if (!address && isnullbad && alloc == NO_ALLOC) + if (pointer && !address && isnullbad && alloc == NO_ALLOC) return true; const bool isuninitbad = _settings->library.isuninitargbad(start->previous(), argumentNumber + 1); if (alloc != NO_ALLOC) diff --git a/test/testuninitvar.cpp b/test/testuninitvar.cpp index af3eed17b..f2a3dff4a 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -1012,6 +1012,13 @@ private: "}"); ASSERT_EQUALS("", errout.str()); + // TODO: write a proper testcase, this can not be compiled + checkUninitVar2("struct X { int x; };\n" + "void f() {\n" + " X var;\n" + " memset(var, 0, sizeof(var));\n" + "}"); + ASSERT_EQUALS("", errout.str()); }