From b1bbb2322586e66c664344e5dc24c2ef0c35eb79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Mon, 13 Jan 2014 05:52:28 +0100 Subject: [PATCH] value flow: fixed fp when checking symboldatabase --- lib/valueflow.cpp | 9 ++++++--- test/testvalueflow.cpp | 8 ++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index b8c863dbb..88624f0c5 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -47,8 +47,8 @@ static void bailout(TokenList *tokenlist, ErrorLogger *errorLogger, const Token static bool bailoutFunctionPar(const Token *tok, const ValueFlow::Value &value, const Settings *settings, bool *inconclusive) { // passing variable to subfunction? - const bool addr = tok && Token::Match(tok->previous(), "&"); - if (!tok || !Token::Match(tok->tokAt(addr?-2:-1), "[(,] &| %var% [,)]")) + const bool addressOf = tok && Token::Match(tok->previous(), "&"); + if (!tok || !Token::Match(tok->tokAt(addressOf?-2:-1), "[(,] &| %var% [,)]")) return false; // goto start of function call and get argnr @@ -69,7 +69,7 @@ static bool bailoutFunctionPar(const Token *tok, const ValueFlow::Value &value, if (value.intvalue==0 && settings->library.isnullargbad(tok->str(), 1+argnr)) return false; // inconclusive => don't bailout - if (inconclusive && !addr && settings->inconclusive) { + if (inconclusive && !addressOf && settings->inconclusive) { *inconclusive = true; return false; } @@ -78,6 +78,9 @@ static bool bailoutFunctionPar(const Token *tok, const ValueFlow::Value &value, const Variable *arg = tok->function()->getArgumentVar(argnr); + if (addressOf && !(arg && arg->isConst())) + return true; + return arg && !arg->isConst() && arg->isReference(); } diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index 787e9c642..7fb5a858f 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -156,6 +156,14 @@ private: "}"; ASSERT_EQUALS(true, testValueOfX(code, 2U, 0)); + code = "void addNewFunction(Scope**scope, const Token**tok);\n" + "void f(Scope *x) {\n" + " x->functionList.back();\n" + " addNewFunction(&x,&tok);\n" // address-of, x can be changed by subfunction + " if (x) {}\n" + "}"; + ASSERT_EQUALS(false, testValueOfX(code, 3U, 0)); + // while, for, do-while code = "void f(int x) {\n" // loop condition, x is not assigned inside loop => use condition " a = x;\n" // x can be 37