From 78225142a8b3c0f95090b089eef32c244ed03551 Mon Sep 17 00:00:00 2001 From: Vasile Vilvoiu Date: Mon, 19 Jul 2021 20:45:04 +0300 Subject: ValueMap constructor sanity checks. --- src/value-map.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'src/value-map.cpp') diff --git a/src/value-map.cpp b/src/value-map.cpp index 8a547c4..2627ed3 100644 --- a/src/value-map.cpp +++ b/src/value-map.cpp @@ -5,9 +5,16 @@ * it under the terms of the MIT license. See LICENSE for details. */ #include "value-map.hpp" +#include ValueMap::ValueMap(double lower, double upper, const std::string& unit) : lower_(lower), upper_(upper), unit_(unit) { + if (std::isnan(lower) || std::isnan(upper) || std::isinf(lower) || std::isinf(upper)) { + throw std::runtime_error("bounds cannot be nan or inf"); + } + if (lower > upper) { + throw std::runtime_error("lower bound cannot exceed upper bound"); + } } std::string @@ -71,4 +78,5 @@ RealWindow DecibelValueMap::Map(const RealWindow &input) std::string DecibelValueMap::GetUnit() const { return "dB" + unit_; -} \ No newline at end of file +} + -- cgit v1.2.3