mirror of
https://gitlab.kitware.com/cmake/cmake.git
synced 2026-09-25 04:09:36 +03:00
math: Avoid FPE on INT_MIN by -1
This commit is contained in:
@@ -190,6 +190,9 @@ std::int64_t cmExprParserHelper::Div(std::int64_t l, std::int64_t r)
|
||||
if (r == 0) {
|
||||
throw std::overflow_error("divide by zero");
|
||||
}
|
||||
if (l == INT64_MIN && r == -1) {
|
||||
throw std::overflow_error("signed integer overflow in division");
|
||||
}
|
||||
return l / r;
|
||||
}
|
||||
|
||||
@@ -198,6 +201,9 @@ std::int64_t cmExprParserHelper::Mod(std::int64_t l, std::int64_t r)
|
||||
if (r == 0) {
|
||||
throw std::overflow_error("modulo by zero");
|
||||
}
|
||||
if (l == INT64_MIN && r == -1) {
|
||||
throw std::overflow_error("signed integer overflow in modulo");
|
||||
}
|
||||
return l % r;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
1
|
||||
@@ -0,0 +1,5 @@
|
||||
^CMake Error at MATH-DivideMinByMinusOne\.cmake:1 \(math\):
|
||||
math cannot evaluate the expression: "~9223372036854775807/-1": signed
|
||||
integer overflow in division\.
|
||||
Call Stack \(most recent call first\):
|
||||
CMakeLists\.txt:3 \(include\)$
|
||||
@@ -0,0 +1 @@
|
||||
math(EXPR var "~9223372036854775807/-1")
|
||||
@@ -0,0 +1 @@
|
||||
1
|
||||
@@ -0,0 +1,5 @@
|
||||
^CMake Error at MATH-ModMinByMinusOne\.cmake:1 \(math\):
|
||||
math cannot evaluate the expression: "~9223372036854775807%-1": signed
|
||||
integer overflow in modulo\.
|
||||
Call Stack \(most recent call first\):
|
||||
CMakeLists\.txt:3 \(include\)$
|
||||
@@ -0,0 +1 @@
|
||||
math(EXPR var "~9223372036854775807%-1")
|
||||
@@ -8,6 +8,8 @@ run_cmake(MATH-InvalidExpression)
|
||||
run_cmake(MATH-ToleratedExpression)
|
||||
run_cmake(MATH-DivideByZero)
|
||||
run_cmake(MATH-ModByZero)
|
||||
run_cmake(MATH-DivideMinByMinusOne)
|
||||
run_cmake(MATH-ModMinByMinusOne)
|
||||
|
||||
if(CMake_TEST_MATH_OVERFLOW)
|
||||
run_cmake_script(Overflow)
|
||||
|
||||
Reference in New Issue
Block a user