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

View File

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