Fix 11053: Integer division by zero in calculate.h (#4092)

* Fix 11053: Integer division by zero in calculate.h

* Format
This commit is contained in:
Paul Fultz II 2022-05-09 13:27:32 -05:00 committed by GitHub
parent 69f09da63e
commit be6daa94bb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 1 deletions

View File

@ -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{};

View File

@ -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() {