Fixed #5105 (false positive: (warning) Either the condition 'b!=0' is useless or there is division by zero)
This commit is contained in:
parent
fd0f2d7900
commit
a55056c770
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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() {
|
||||
|
|
Loading…
Reference in New Issue