From a735790e7756a8502fd8d64f1c9acadc26b66eef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Fri, 19 Aug 2011 18:55:20 +0200 Subject: [PATCH] using boolean result in bitwise operation. fix false positive for '.. != (char *) &x' --- lib/checkother.cpp | 9 ++++++++- test/testother.cpp | 5 +++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index c5b10d7e0..f9d1c2204 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -169,9 +169,16 @@ void CheckOther::clarifyCondition() // using boolean result in bitwise operation ! x [&|^] for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next()) { - if (Token::Match(tok, "!|<|<=|==|!=|>|>= !!&")) + if (Token::Match(tok, "!|<|<=|==|!=|>|>=")) { const Token *tok2 = tok->next(); + + // Todo: There are false positives if '(' if encountered. It + // is assumed there is something like '(char *)&..' and therefore + // it bails out. + if (Token::Match(tok2, "(|&")) + continue; + while (tok2 && (tok2->isName() || tok2->isNumber() || Token::Match(tok2,".|(|["))) { if (Token::Match(tok2, "(|[")) diff --git a/test/testother.cpp b/test/testother.cpp index 1487949d8..651a2a14b 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -2682,6 +2682,11 @@ private: check("void f() { A a; }"); ASSERT_EQUALS("", errout.str()); + + check("void f() {\n" + " if (result != (char *)&inline_result) { }\n" + "}"); + ASSERT_EQUALS("", errout.str()); } void incorrectStringCompare()