value flow: fixed fp when checking symboldatabase
This commit is contained in:
parent
f6c7be91a9
commit
b1bbb23225
|
@ -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)
|
static bool bailoutFunctionPar(const Token *tok, const ValueFlow::Value &value, const Settings *settings, bool *inconclusive)
|
||||||
{
|
{
|
||||||
// passing variable to subfunction?
|
// passing variable to subfunction?
|
||||||
const bool addr = tok && Token::Match(tok->previous(), "&");
|
const bool addressOf = tok && Token::Match(tok->previous(), "&");
|
||||||
if (!tok || !Token::Match(tok->tokAt(addr?-2:-1), "[(,] &| %var% [,)]"))
|
if (!tok || !Token::Match(tok->tokAt(addressOf?-2:-1), "[(,] &| %var% [,)]"))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// goto start of function call and get argnr
|
// 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))
|
if (value.intvalue==0 && settings->library.isnullargbad(tok->str(), 1+argnr))
|
||||||
return false;
|
return false;
|
||||||
// inconclusive => don't bailout
|
// inconclusive => don't bailout
|
||||||
if (inconclusive && !addr && settings->inconclusive) {
|
if (inconclusive && !addressOf && settings->inconclusive) {
|
||||||
*inconclusive = true;
|
*inconclusive = true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -78,6 +78,9 @@ static bool bailoutFunctionPar(const Token *tok, const ValueFlow::Value &value,
|
||||||
|
|
||||||
const Variable *arg = tok->function()->getArgumentVar(argnr);
|
const Variable *arg = tok->function()->getArgumentVar(argnr);
|
||||||
|
|
||||||
|
if (addressOf && !(arg && arg->isConst()))
|
||||||
|
return true;
|
||||||
|
|
||||||
return arg && !arg->isConst() && arg->isReference();
|
return arg && !arg->isConst() && arg->isReference();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -156,6 +156,14 @@ private:
|
||||||
"}";
|
"}";
|
||||||
ASSERT_EQUALS(true, testValueOfX(code, 2U, 0));
|
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
|
// while, for, do-while
|
||||||
code = "void f(int x) {\n" // loop condition, x is not assigned inside loop => use condition
|
code = "void f(int x) {\n" // loop condition, x is not assigned inside loop => use condition
|
||||||
" a = x;\n" // x can be 37
|
" a = x;\n" // x can be 37
|
||||||
|
|
Loading…
Reference in New Issue