Prevent potential division by zero

This commit is contained in:
Mikhail Khachayants 2024-10-20 13:19:49 +03:00
parent fc9ddf14db
commit 63c56dd730

View File

@ -19,6 +19,7 @@
#include <set>
#include <string>
#include <vector>
#include <cmath>
#include <valijson/constraints/basic_constraint.hpp>
#include <valijson/internal/custom_allocator.hpp>
@ -784,6 +785,11 @@ public:
void setDivisor(double newValue)
{
if (!std::isfinite(newValue) || newValue <= 0.0) {
throwRuntimeError(
"Divisor for 'multipleOf' or 'divisibleBy' must be positive");
}
m_value = newValue;
}
@ -813,6 +819,11 @@ public:
void setDivisor(int64_t newValue)
{
if (newValue <= 0) {
throwRuntimeError(
"Divisor for 'multipleOf' or 'divisibleBy' must be positive");
}
m_value = newValue;
}