diff options
author | Ed Tanous <ed@tanous.net> | 2024-04-08 00:05:05 +0300 |
---|---|---|
committer | Ed Tanous <ed@tanous.net> | 2024-04-11 21:21:12 +0300 |
commit | c09966bdaac3b31e6a4b6adc75cc7481727f6c99 (patch) | |
tree | ac0dbc83296904ae43a68ebf6f61c717579999b7 /redfish-core/include/utils | |
parent | 44106f346d79f6d740d4f756fe55ece78bb7feed (diff) | |
download | bmcweb-c09966bdaac3b31e6a4b6adc75cc7481727f6c99.tar.xz |
Give static analysis some hints
Static analysis tools complain that for certain template types, these
comparisons do nothing. Doing nothing is what they're intended to do,
as we have other checks.
Add some constexpr if hints so static analysis tools don't complain.
Change-Id: I60297d094626936d021382ccdc11e4c8b698e3d8
Signed-off-by: Ed Tanous <ed@tanous.net>
Diffstat (limited to 'redfish-core/include/utils')
-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; } } |