diff --git a/lib/calculate.h b/lib/calculate.h index 663d2939a..3e62e212b 100644 --- a/lib/calculate.h +++ b/lib/calculate.h @@ -69,7 +69,7 @@ R calculate(const std::string& s, const T& x, const T& y, bool* error = nullptr) } return wrap(x / y); case '%': - if (isZero(y)) { + if (isZero(MathLib::bigint(y))) { if (error) *error = true; return R{}; diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index e729a7b6b..0760df72a 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -6519,6 +6519,20 @@ private: code = "void f(const char * const x) { !!system(x); }\n"; valueOfTok(code, "x"); + + code = "void setDeltas(int life, int age, int multiplier) {\n" + " int dx = 0;\n" + " int dy = 0;\n" + " if (age <= 2 || life < 4) {\n" + " dy = 0;\n" + " dx = (rand() % 3) - 1;\n" + " }\n" + " else if (age < (multiplier * 3)) {\n" + " if (age % (int) (multiplier * 0.5) == 0) dy = -1;\n" + " else dy = 0;\n" + " }\n" + "}\n"; + valueOfTok(code, "age"); } void valueFlowHang() {