Fix issue 10076: ValueFlow: False positive after address of var is taken 'T t = {{&var}};' (#3027)

This commit is contained in:
Paul Fultz II 2021-01-08 03:29:32 -06:00 committed by GitHub
parent bedf3118ef
commit 3b5c558414
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 1 deletions

View File

@ -2150,7 +2150,7 @@ const ::Type *Token::typeOf(const Token *tok)
if (!function)
return nullptr;
return function->retType;
} else if (Token::Match(tok->previous(), "%type% (|{")) {
} else if (Token::Match(tok->previous(), "%type%|= (|{")) {
return typeOf(tok->previous());
} else if (Token::simpleMatch(tok, "=")) {
return Token::typeOf(tok->astOperand1());

View File

@ -365,6 +365,21 @@ private:
"test.cpp:2:note:condition 'v.size()==1'\n"
"test.cpp:3:note:Access out of bounds\n",
errout.str());
check("struct T {\n"
" std::vector<int>* v;\n"
"};\n"
"struct S {\n"
" T t;\n"
"};\n"
"long g(S& s);\n"
"int f() {\n"
" std::vector<int> ArrS;\n"
" S s = { { &ArrS } };\n"
" g(s);\n"
" return ArrS[0];\n"
"}\n", true);
ASSERT_EQUALS("", errout.str());
}
void outOfBoundsIndexExpression() {