Fix issue 10076: ValueFlow: False positive after address of var is taken 'T t = {{&var}};' (#3027)
This commit is contained in:
parent
bedf3118ef
commit
3b5c558414
|
@ -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());
|
||||
|
|
|
@ -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() {
|
||||
|
|
Loading…
Reference in New Issue