From c3e47f7eaa0399553e66a7d12df5a1ee3de3710f Mon Sep 17 00:00:00 2001 From: PKEuS Date: Wed, 21 Jan 2015 22:26:44 +0100 Subject: [PATCH] Fixed false positive in CheckUninitVar and internal message --- lib/checkuninitvar.cpp | 8 +++++++- test/testuninitvar.cpp | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/checkuninitvar.cpp b/lib/checkuninitvar.cpp index 58a419fb7..8cf741982 100644 --- a/lib/checkuninitvar.cpp +++ b/lib/checkuninitvar.cpp @@ -1438,7 +1438,7 @@ bool CheckUninitVar::checkScopeForVariable(const Scope* scope, const Token *tok, } // bailout on ternary operator. TODO: This can be solved much better. For example, if the variable is not accessed in the branches of the ternary operator, we could just continue. - if (Token::Match(tok, "?")) { + if (tok->str() == "?") { return true; } @@ -1706,6 +1706,12 @@ bool CheckUninitVar::isVariableUsage(const Token *vartok, bool pointer, bool all assignment = true; break; } + if (alloc && parent->str() == "(") { + if (_settings->library.functionpure.find(parent->strAt(-1)) == _settings->library.functionpure.end()) { + assignment = true; + break; + } + } parent = parent->astParent(); } if (!assignment) diff --git a/test/testuninitvar.cpp b/test/testuninitvar.cpp index c5542076b..c9aecdb0a 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -1470,7 +1470,7 @@ private: " Fred *fred = malloc(sizeof(Fred));\n" " x(fred->f);\n" "};"); - TODO_ASSERT_EQUALS("", "[test.cpp:4]: (error) Memory is allocated but not initialized: fred\n", errout.str()); + ASSERT_EQUALS("", errout.str()); checkUninitVarB("void foo(char *s)\n" "{\n"