Fixed #5105 (false positive: (warning) Either the condition 'b!=0' is useless or there is division by zero)

This commit is contained in:
Daniel Marjamäki 2013-10-22 16:18:42 +02:00
parent fd0f2d7900
commit a55056c770
2 changed files with 11 additions and 0 deletions

View File

@ -2267,6 +2267,10 @@ void CheckOther::checkZeroDivisionOrUselessCondition()
zerodivcondError(tok2,divtok);
else if (isVarUnsigned && Token::Match(tok2, "(|%oror%|&& 1 <= %varid% &&|%oror%|)", varid))
zerodivcondError(tok2,divtok);
else if (Token::Match(tok2, "%var% ("))
// Todo: continue looking in condition unless variable might be
// changed by the function
break;
else if (Token::Match(tok2, "(|%oror%|&& !| %varid% &&|%oror%|)", varid))
zerodivcondError(tok2,divtok);
}

View File

@ -578,6 +578,13 @@ private:
CheckOther checkOther(&tokenizer, &settings, this);
checkOther.checkZeroDivisionOrUselessCondition(); // don't crash
}
// #5105 - FP
check("int f(int a, int b) {\n"
" int r = a / b;\n"
" if (func(b)) {}\n"
"}");
ASSERT_EQUALS("", errout.str());
}
void nanInArithmeticExpression() {