value flow: fixed fp when checking symboldatabase

This commit is contained in:
Daniel Marjamäki 2014-01-13 05:52:28 +01:00
parent f6c7be91a9
commit b1bbb23225
2 changed files with 14 additions and 3 deletions

View File

@ -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();
}

View File

@ -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