diff options
Diffstat (limited to 'redfish-core')
-rw-r--r-- | redfish-core/include/utils/json_utils.hpp | 33 |
1 files changed, 21 insertions, 12 deletions
diff --git a/redfish-core/include/utils/json_utils.hpp b/redfish-core/include/utils/json_utils.hpp index df0c86ebb0..d7d87a60cf 100644 --- a/redfish-core/include/utils/json_utils.hpp +++ b/redfish-core/include/utils/json_utils.hpp @@ -106,25 +106,34 @@ enum class UnpackErrorCode }; template <typename ToType, typename FromType> -bool checkRange(const FromType& from, std::string_view key) +bool checkRange(const FromType& from [[maybe_unused]], + std::string_view key [[maybe_unused]]) { - if (from > std::numeric_limits<ToType>::max()) + if constexpr (std::is_floating_point_v<ToType>) { - BMCWEB_LOG_DEBUG("Value for key {} was greater than max: {}", key, - __PRETTY_FUNCTION__); - return false; + if (std::isnan(from)) + { + BMCWEB_LOG_DEBUG("Value for key {} was NAN", key); + return false; + } } - if (from < std::numeric_limits<ToType>::lowest()) + if constexpr (std::numeric_limits<ToType>::max() < + std::numeric_limits<FromType>::max()) { - BMCWEB_LOG_DEBUG("Value for key {} was less than min: {}", key, - __PRETTY_FUNCTION__); - return false; + if (from > std::numeric_limits<ToType>::max()) + { + BMCWEB_LOG_DEBUG("Value for key {} was greater than max {}", key, + std::numeric_limits<FromType>::max()); + return false; + } } - if constexpr (std::is_floating_point_v<ToType>) + if constexpr (std::numeric_limits<ToType>::lowest() > + std::numeric_limits<FromType>::lowest()) { - if (std::isnan(from)) + if (from < std::numeric_limits<ToType>::lowest()) { - BMCWEB_LOG_DEBUG("Value for key {} was NAN", key); + BMCWEB_LOG_DEBUG("Value for key {} was less than min {}", key, + std::numeric_limits<FromType>::lowest()); return false; } } |