diff options
| author | Ed Tanous <ed.tanous@intel.com> | 2019-08-08 08:38:08 -0700 |
|---|---|---|
| committer | Ed Tanous <ed.tanous@intel.com> | 2019-09-04 20:35:40 +0000 |
| commit | ee344e0fa76b2b24866d25b305e12ae82824f01b (patch) | |
| tree | d17b1cba1e89cc752e77ce4ff48401aa309c7ae6 /redfish-core/include | |
| parent | cf05f9dc31a47123521348bc870fc687e3f35b4c (diff) | |
| download | bmcweb-ee344e0fa76b2b24866d25b305e12ae82824f01b.tar.gz bmcweb-ee344e0fa76b2b24866d25b305e12ae82824f01b.zip | |
cleanup: Move a pointer to a reference
Minor cleanup to a routine that allows us to drop one nullptr check.
Tested:
Will test shortly. Code should be no-op.
Signed-off-by: Ed Tanous <ed.tanous@intel.com>
Change-Id: I592dc0a9a311d6dd885cdd6289f343dd4b9b0567
Diffstat (limited to 'redfish-core/include')
| -rw-r--r-- | redfish-core/include/utils/json_utils.hpp | 22 |
1 files changed, 7 insertions, 15 deletions
diff --git a/redfish-core/include/utils/json_utils.hpp b/redfish-core/include/utils/json_utils.hpp index 775de64..3ef70dc 100644 --- a/redfish-core/include/utils/json_utils.hpp +++ b/redfish-core/include/utils/json_utils.hpp @@ -79,25 +79,17 @@ template <typename Type> constexpr bool is_std_array_v = is_std_array<Type>::value; template <typename ToType, typename FromType> -bool checkRange(const FromType* from, const std::string& key, +bool checkRange(const FromType& from, const std::string& key, nlohmann::json& jsonValue, crow::Response& res) { - if (from == nullptr) - { - BMCWEB_LOG_DEBUG << "Value for key " << key - << " was incorrect type: " << __PRETTY_FUNCTION__; - messages::propertyValueTypeError(res, jsonValue.dump(), key); - return false; - } - - if (*from > std::numeric_limits<ToType>::max()) + if (from > std::numeric_limits<ToType>::max()) { BMCWEB_LOG_DEBUG << "Value for key " << key << " was greater than max: " << __PRETTY_FUNCTION__; messages::propertyValueNotInList(res, jsonValue.dump(), key); return false; } - if (*from < std::numeric_limits<ToType>::lowest()) + if (from < std::numeric_limits<ToType>::lowest()) { BMCWEB_LOG_DEBUG << "Value for key " << key << " was less than min: " << __PRETTY_FUNCTION__; @@ -106,7 +98,7 @@ bool checkRange(const FromType* from, const std::string& key, } if constexpr (std::is_floating_point_v<ToType>) { - if (std::isnan(*from)) + if (std::isnan(from)) { BMCWEB_LOG_DEBUG << "Value for key " << key << " was NAN"; messages::propertyValueNotInList(res, jsonValue.dump(), key); @@ -137,7 +129,7 @@ bool unpackValue(nlohmann::json& jsonValue, const std::string& key, jsonPtr = &helper; } } - if (!checkRange<Type>(jsonPtr, key, jsonValue, res)) + if (!checkRange<Type>(*jsonPtr, key, jsonValue, res)) { return false; } @@ -147,7 +139,7 @@ bool unpackValue(nlohmann::json& jsonValue, const std::string& key, else if constexpr (std::is_signed_v<Type>) { int64_t* jsonPtr = jsonValue.get_ptr<int64_t*>(); - if (!checkRange<Type>(jsonPtr, key, jsonValue, res)) + if (!checkRange<Type>(*jsonPtr, key, jsonValue, res)) { return false; } @@ -158,7 +150,7 @@ bool unpackValue(nlohmann::json& jsonValue, const std::string& key, !std::is_same_v<bool, Type>)) { uint64_t* jsonPtr = jsonValue.get_ptr<uint64_t*>(); - if (!checkRange<Type>(jsonPtr, key, jsonValue, res)) + if (!checkRange<Type>(*jsonPtr, key, jsonValue, res)) { return false; } |

