From 80dec5a976625e6d0ee457d2815109823a3da2a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Fri, 13 Dec 2013 20:10:22 +0100 Subject: [PATCH] Uninitialized variables: Fixed FP when taking address of uninitialized variable --- lib/checkuninitvar.cpp | 2 +- test/testuninitvar.cpp | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/checkuninitvar.cpp b/lib/checkuninitvar.cpp index abdccd77b..d9c624a12 100644 --- a/lib/checkuninitvar.cpp +++ b/lib/checkuninitvar.cpp @@ -1726,7 +1726,7 @@ bool CheckUninitVar::isVariableUsage(const Token *vartok, bool pointer, bool all // is there something like: ; "*((&var ..expr.. =" => the variable is assigned if (vartok->previous()->str() == "&") { const Token *tok2 = vartok->tokAt(-2); - if (tok2 && (tok2->isConstOp() || Token::Match(tok2, "[;{}(]"))) + if (tok2 && (tok2->isConstOp() || Token::Match(tok2, "[;{}(=]"))) return false; // address of if (tok2 && tok2->str() == ")") tok2 = tok2->link()->previous(); diff --git a/test/testuninitvar.cpp b/test/testuninitvar.cpp index d525fc55b..328ae3713 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -2142,6 +2142,12 @@ private: "}"); ASSERT_EQUALS("", errout.str()); + checkUninitVar2("void f() {\n" + " int x;\n" + " char *p = (char*)&x + 1;\n" + "}", "test.cpp", false); // verify=false (the cast is removed but we don't care) + ASSERT_EQUALS("", errout.str()); + checkUninitVar2("void f() {\n" " int i;\n" " i=f(), i!=2;\n"