diff --git a/lib/checkother.cpp b/lib/checkother.cpp index e89b72599..d04a8ae1e 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -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); } diff --git a/test/testother.cpp b/test/testother.cpp index 927792ba0..793c9c2de 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -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() {