Correct false positives compareBoolExpressionWithInt (0U)

This commit is contained in:
Alexander Mai 2016-02-19 21:38:54 +01:00
parent 0fc59d0228
commit 5c2960713f
2 changed files with 16 additions and 2 deletions

View File

@ -353,11 +353,12 @@ void CheckBool::checkComparisonOfBoolExpressionWithInt()
continue;
if (numTok->isNumber()) {
if (numTok->str() == "0" &&
const MathLib::bigint num = MathLib::toLongNumber(numTok->str());
if (num==0 &&
(numInRhs ? Token::Match(tok, ">|==|!=")
: Token::Match(tok, "<|==|!=")))
continue;
if (numTok->str() == "1" &&
if (num==1 &&
(numInRhs ? Token::Match(tok, "<|==|!=")
: Token::Match(tok, ">|==|!=")))
continue;

View File

@ -538,6 +538,19 @@ private:
" return a > b or c < d;\n"
"}");
ASSERT_EQUALS("", errout.str());
check("int f() {\n"
" return (a < b) != 0U;\n"
"}");
ASSERT_EQUALS("", errout.str());
check("int f() {\n"
" return (a < b) != 0x0;\n"
"}");
ASSERT_EQUALS("", errout.str());
check("int f() {\n"
" return (a < b) != 42U;\n"
"}");
ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean expression with an integer other than 0 or 1.\n", errout.str());
}
void checkComparisonOfFuncReturningBool1() {