From 7778c082e9b15774a1e79ab77cb60edb5c3a2949 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Fri, 1 Sep 2017 21:51:33 +0300 Subject: Add some checks after automatic check code by tools. --- src/configuration.cpp | 49 +++++++++++++++++++++++++++++++++---------------- 1 file changed, 33 insertions(+), 16 deletions(-) (limited to 'src/configuration.cpp') diff --git a/src/configuration.cpp b/src/configuration.cpp index 94fa433f5..d3c514c67 100644 --- a/src/configuration.cpp +++ b/src/configuration.cpp @@ -458,19 +458,28 @@ int Configuration::resetIntValue(const std::string &key) GETLOG(); int defaultValue = 0; const DefaultsData::const_iterator itdef = mDefaultsData.find(key); - const VariableData *const data = itdef->second; - if (itdef != mDefaultsData.end() && data != nullptr - && data->getType() == VariableData::DATA_INT) - { - defaultValue = (static_cast( - data))->getData(); - } - else + if (itdef == mDefaultsData.end()) { reportAlways("%s: No integer value in registry for key %s", mConfigPath.c_str(), key.c_str()); } + else + { + const VariableData *const data = itdef->second; + if (data != nullptr && + data->getType() == VariableData::DATA_INT) + { + defaultValue = (static_cast( + data))->getData(); + } + else + { + reportAlways("%s: No integer value in registry for key %s", + mConfigPath.c_str(), + key.c_str()); + } + } setValue(key, defaultValue); return defaultValue; } @@ -658,20 +667,28 @@ bool Configuration::resetBoolValue(const std::string &key) GETLOG(); bool defaultValue = false; const DefaultsData::const_iterator itdef = mDefaultsData.find(key); - const VariableData *const data = itdef->second; - if (itdef != mDefaultsData.end() && - (data != nullptr) && - data->getType() == VariableData::DATA_BOOL) - { - defaultValue = (static_cast(data))->getData(); - } - else + if (itdef == mDefaultsData.end()) { reportAlways("%s: No boolean value in registry for key %s", mConfigPath.c_str(), key.c_str()); } + else + { + const VariableData *const data = itdef->second; + if (data != nullptr && + data->getType() == VariableData::DATA_BOOL) + { + defaultValue = (static_cast(data))->getData(); + } + else + { + reportAlways("%s: No boolean value in registry for key %s", + mConfigPath.c_str(), + key.c_str()); + } + } setValue(key, defaultValue); return defaultValue; -- cgit v1.2.3-60-g2f50