AST: Fixed iscast detection in '*((DWORD*)&buf[0])'

This commit is contained in:
Daniel Marjamäki 2014-04-15 15:46:26 +02:00
parent 3d0217b69e
commit 5c116c622d
2 changed files with 9 additions and 2 deletions

View File

@ -391,8 +391,12 @@ static bool iscast(const Token *tok)
return false;
for (const Token *tok2 = tok->next(); tok2; tok2 = tok2->next()) {
if (tok2->str() == ")")
return tok2->previous()->str() == "*" ||
(Token::Match(tok2, ") %any%") &&
(!tok2->next()->isOp() && !Token::Match(tok2->next(), "[[]);,?:]")));
if (!Token::Match(tok2, "%var%|*|&|::"))
return Token::Match(tok2, ") %any%") && (!tok2->next()->isOp() && !Token::Match(tok2->next(), "[[]);,?:]"));
return false;
}
return false;

View File

@ -10240,6 +10240,10 @@ private:
ASSERT_EQUALS("pf.pf.12,(&&", testAst("((p.f) && (p.f)(1,2))"));
// problems with: if (x[y]==z)
ASSERT_EQUALS("ifa(0[1==(", testAst("if(a()[0]==1){}"));
ASSERT_EQUALS("ifbuff0[&(*1==(", testAst("if (*((DWORD*)&buff[0])==1){}"));
// casts
ASSERT_EQUALS("a1(2(+=",testAst("a=(t)1+(t)2;"));
ASSERT_EQUALS("a1(2+=",testAst("a=(t)1+2;"));
@ -10257,7 +10261,6 @@ private:
ASSERT_EQUALS("QT_WA{{,( QT_WA{{,( x1=",
testAst("QT_WA({},{x=0;});" // don't hang
"QT_WA({x=1;},{x=2;});"));
ASSERT_EQUALS("ifa(0[1==(", testAst("if(a()[0]==1){}"));
}
void astbrackets() const { // []