mirror of
https://github.com/tristanpenman/valijson.git
synced 2024-12-12 10:13:51 +01:00
Prevent potential division by zero
This commit is contained in:
parent
fc9ddf14db
commit
63c56dd730
@ -19,6 +19,7 @@
|
|||||||
#include <set>
|
#include <set>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <cmath>
|
||||||
|
|
||||||
#include <valijson/constraints/basic_constraint.hpp>
|
#include <valijson/constraints/basic_constraint.hpp>
|
||||||
#include <valijson/internal/custom_allocator.hpp>
|
#include <valijson/internal/custom_allocator.hpp>
|
||||||
@ -784,6 +785,11 @@ public:
|
|||||||
|
|
||||||
void setDivisor(double newValue)
|
void setDivisor(double newValue)
|
||||||
{
|
{
|
||||||
|
if (!std::isfinite(newValue) || newValue <= 0.0) {
|
||||||
|
throwRuntimeError(
|
||||||
|
"Divisor for 'multipleOf' or 'divisibleBy' must be positive");
|
||||||
|
}
|
||||||
|
|
||||||
m_value = newValue;
|
m_value = newValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -813,6 +819,11 @@ public:
|
|||||||
|
|
||||||
void setDivisor(int64_t newValue)
|
void setDivisor(int64_t newValue)
|
||||||
{
|
{
|
||||||
|
if (newValue <= 0) {
|
||||||
|
throwRuntimeError(
|
||||||
|
"Divisor for 'multipleOf' or 'divisibleBy' must be positive");
|
||||||
|
}
|
||||||
|
|
||||||
m_value = newValue;
|
m_value = newValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user