Fixed #5077 (False positive: Comparison of boolean result with relational operator ((X + (Y < 0)) <= b))

This commit is contained in:
Daniel Marjamäki 2013-10-09 05:43:50 +02:00
parent 9dfb950776
commit 682e68b1b6
2 changed files with 11 additions and 14 deletions

View File

@ -364,25 +364,19 @@ static bool isNonBoolLHSExpr(const Token *tok)
// return value. only return true if we "know" it's a non-bool expression
bool nonBoolExpr = false;
// look into () and []
int indentlevel = 0;
for (; tok; tok = tok->previous()) {
if (tok->str() == ")" || tok->str() == "]")
++indentlevel;
else if (tok->str() == "(" || tok->str() == "[") {
if (indentlevel <= 0)
if (tok->str() == ")") {
if (!Token::Match(tok->link()->previous(), "&&|%oror%|( ("))
tok = tok->link();
} else if (tok->str() == "(" || tok->str() == "[")
break;
--indentlevel;
} else if (tok->isNumber())
else if (tok->isNumber())
nonBoolExpr = true;
else if (tok->isArithmeticalOp()) {
if (indentlevel == 0)
return true;
nonBoolExpr = true;
} else if (tok->isComparisonOp() || (tok->str() == "!" && tok->previous()->str()=="("))
return false;
else if (indentlevel == 0 && Token::Match(tok,"[;{}=?:&|^,]"))
else if (Token::Match(tok,"[;{}=?:&|^,]"))
break;
else if (Token::Match(tok, "&&|%oror%|and|or"))
break;

View File

@ -322,6 +322,9 @@ private:
check(code, false, "test.c");
ASSERT_EQUALS("", errout.str());
}
check("int f() { return (a+(b<5)<=c); }");
ASSERT_EQUALS("",errout.str());
}
void comparisonOfBoolExpressionWithInt2() {