Merge pull request #198 from tyler92/division-by-zero

Prevent potential division by zero
This commit is contained in:
Tristan Penman 2024-10-21 08:43:50 +11:00 committed by GitHub
commit 7fd212f68d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

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