diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 29c52e771..792538eff 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -2570,6 +2570,13 @@ void CheckOther::checkMathFunctions() { mathfunctionCallError(tok,2); } + // fmod ( x , y) If y is zero, then either a range error will occur or the function will return zero (implementation-defined). + else if (Token::Match(tok, "fmod ( %num% , %num% )") && + MathLib::isNullValue(tok->tokAt(4)->str())) + { + mathfunctionCallError(tok,2); + } + } } diff --git a/test/testother.cpp b/test/testother.cpp index a5023fb19..c0abeb9c6 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -2306,6 +2306,12 @@ private: "}"); ASSERT_EQUALS("[test.cpp:3]: (error) Passing value 0 and 0 to atan2() leads to undefined result\n", errout.str()); + check("void foo()\n" + "{\n" + " std::cout << fmod(1.0,0) << std::endl;\n" + "}"); + ASSERT_EQUALS("[test.cpp:3]: (error) Passing value 1.0 and 0 to fmod() leads to undefined result\n", errout.str()); + } };