Skip to content

Commit be6daa9

Browse files
authored
Fix 11053: Integer division by zero in calculate.h (#4092)
* Fix 11053: Integer division by zero in calculate.h * Format
1 parent 69f09da commit be6daa9

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

lib/calculate.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ R calculate(const std::string& s, const T& x, const T& y, bool* error = nullptr)
6969
}
7070
return wrap(x / y);
7171
case '%':
72-
if (isZero(y)) {
72+
if (isZero(MathLib::bigint(y))) {
7373
if (error)
7474
*error = true;
7575
return R{};

test/testvalueflow.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6519,6 +6519,20 @@ class TestValueFlow : public TestFixture {
65196519

65206520
code = "void f(const char * const x) { !!system(x); }\n";
65216521
valueOfTok(code, "x");
6522+
6523+
code = "void setDeltas(int life, int age, int multiplier) {\n"
6524+
" int dx = 0;\n"
6525+
" int dy = 0;\n"
6526+
" if (age <= 2 || life < 4) {\n"
6527+
" dy = 0;\n"
6528+
" dx = (rand() % 3) - 1;\n"
6529+
" }\n"
6530+
" else if (age < (multiplier * 3)) {\n"
6531+
" if (age % (int) (multiplier * 0.5) == 0) dy = -1;\n"
6532+
" else dy = 0;\n"
6533+
" }\n"
6534+
"}\n";
6535+
valueOfTok(code, "age");
65226536
}
65236537

65246538
void valueFlowHang() {

0 commit comments

Comments
 (0)