Fixed #9424 (False positive: known condition after function call)

This commit is contained in:
Daniel Marjamäki 2019-10-18 08:21:07 +02:00
parent 478625c802
commit 3a0a0fdefb
2 changed files with 19 additions and 1 deletions

View File

@ -5770,7 +5770,7 @@ static bool isContainerSizeChangedByFunction(const Token *tok, int depth = 20)
return false;
// address of variable
const bool addressOf = tok->astParent() && tok->astParent()->isUnaryOp("&");
const bool addressOf = tok->valueType()->pointer || (tok->astParent() && tok->astParent()->isUnaryOp("&"));
int narg;
const Token * ftok = getTokenArgumentFunction(tok, narg);
@ -5792,6 +5792,8 @@ static bool isContainerSizeChangedByFunction(const Token *tok, int depth = 20)
if (depth > 0)
return isContainerSizeChanged(arg->declarationId(), scope->bodyStart, scope->bodyEnd, depth - 1);
}
// Don't know => Safe guess
return true;
}
}

View File

@ -4144,6 +4144,22 @@ private:
"}";
ASSERT(tokenValues(code, "ints [").empty());
code = "struct A {\n" // forward, nested function call, #9424
" double getMessage( std::vector<unsigned char> *message );\n"
"};\n"
"\n"
"struct B {\n"
" A *a;\n"
" double getMessage( std::vector<unsigned char> *message ) { return a->getMessage( message ); }\n"
"};\n"
"\n"
"void foo(B *ptr) {\n"
" std::vector<unsigned char> v;\n"
" ptr->getMessage (&v);\n"
" if (v.size () > 0) {}\n" // <- v has unknown size!
"}";
ASSERT_EQUALS(0U, tokenValues(code, "v . size ( )").size());
// container size => yields
code = "void f() {\n"
" std::string s = \"abcd\";\n"