From 5c116c622d2a8d52fc5705dc146653f53d6d35b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Tue, 15 Apr 2014 15:46:26 +0200 Subject: [PATCH] AST: Fixed iscast detection in '*((DWORD*)&buf[0])' --- lib/tokenlist.cpp | 6 +++++- test/testtokenize.cpp | 5 ++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/tokenlist.cpp b/lib/tokenlist.cpp index 813a1cf7f..dcbc75aba 100644 --- a/lib/tokenlist.cpp +++ b/lib/tokenlist.cpp @@ -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; diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 320923a7f..9259b7d3f 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -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 { // []