From 659fcf8fa33307eaeb7a57cf9f733138036e1712 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Wed, 6 Mar 2013 15:41:13 +0100 Subject: [PATCH] Fix cppcheck warnings. --- components/compat/compatcomponent.cpp | 13 ------------- components/delegation/delegationcomponent.cpp | 8 ++------ lib/base/dynamicobject.cpp | 6 +++--- lib/config/configtype.cpp | 2 +- lib/icinga/externalcommandprocessor.cpp | 2 +- lib/icinga/notification.cpp | 2 +- lib/icinga/service-comment.cpp | 2 +- lib/icinga/service-downtime.cpp | 2 +- lib/icinga/service-notification.cpp | 2 +- lib/remoting/endpointmanager.cpp | 2 +- 10 files changed, 12 insertions(+), 29 deletions(-) diff --git a/components/compat/compatcomponent.cpp b/components/compat/compatcomponent.cpp index ae0219463..fa0c187d7 100644 --- a/components/compat/compatcomponent.cpp +++ b/components/compat/compatcomponent.cpp @@ -270,22 +270,9 @@ void CompatComponent::DumpHostStatus(ostream& fp, const Host::Ptr& host) fp << "hoststatus {" << "\n" << "\t" << "host_name=" << host->GetName() << "\n"; - ServiceState hcState = StateOK; - Service::Ptr hc = host->GetHostCheckService(); ObjectLock olock(hc); - if (hc) - hcState = hc->GetState(); - - int state; - if (!host->IsReachable()) - state = 2; /* unreachable */ - else if (hcState != StateOK) - state = 1; /* down */ - else - state = 0; /* up */ - if (hc) DumpServiceStatusAttrs(fp, hc, CompatTypeHost); diff --git a/components/delegation/delegationcomponent.cpp b/components/delegation/delegationcomponent.cpp index 10109d4e8..eb37f7474 100644 --- a/components/delegation/delegationcomponent.cpp +++ b/components/delegation/delegationcomponent.cpp @@ -104,8 +104,6 @@ void DelegationComponent::DelegationTimerHandler(void) histogram[endpoint]++; } - //std::random_shuffle(services.begin(), services.end()); - int delegated = 0; /* re-assign services */ @@ -119,9 +117,7 @@ void DelegationComponent::DelegationTimerHandler(void) int avg_services = 0, overflow_tolerance = 0; vector::iterator cit; - if (candidates.size() > 0) { - //std::random_shuffle(candidates.begin(), candidates.end()); - + if (!candidates.empty()) { stringstream msgbuf; msgbuf << "Service: " << service->GetName() << ", candidates: " << candidates.size(); Logger::Write(LogDebug, "delegation", msgbuf.str()); @@ -176,7 +172,7 @@ void DelegationComponent::DelegationTimerHandler(void) break; } - if (candidates.size() == 0) { + if (candidates.empty()) { if (service->GetState() != StateUncheckable && service->GetEnableActiveChecks()) { Dictionary::Ptr cr = boost::make_shared(); diff --git a/lib/base/dynamicobject.cpp b/lib/base/dynamicobject.cpp index df9c382ce..7cf332d10 100644 --- a/lib/base/dynamicobject.cpp +++ b/lib/base/dynamicobject.cpp @@ -79,7 +79,7 @@ Dictionary::Ptr DynamicObject::BuildUpdate(double sinceTx, int attributeTypes) c { boost::mutex::scoped_lock lock(m_AttributeMutex); - for (it = m_Attributes.begin(); it != m_Attributes.end(); it++) { + for (it = m_Attributes.begin(); it != m_Attributes.end(); ++it) { if (it->second.GetType() == Attribute_Transient) continue; @@ -132,7 +132,7 @@ void DynamicObject::ApplyUpdate(const Dictionary::Ptr& serializedUpdate, if (configTx > m_ConfigTx) { DynamicObject::AttributeIterator at; - for (at = m_Attributes.begin(); at != m_Attributes.end(); at++) { + for (at = m_Attributes.begin(); at != m_Attributes.end(); ++at) { if ((at->second.GetType() & Attribute_Config) == 0) continue; @@ -149,7 +149,7 @@ void DynamicObject::ApplyUpdate(const Dictionary::Ptr& serializedUpdate, ObjectLock alock(attrs); Dictionary::Iterator it; - for (it = attrs->Begin(); it != attrs->End(); it++) { + for (it = attrs->Begin(); it != attrs->End(); ++it) { if (!it->second.IsObjectType()) continue; diff --git a/lib/config/configtype.cpp b/lib/config/configtype.cpp index 85234ef43..669269c80 100644 --- a/lib/config/configtype.cpp +++ b/lib/config/configtype.cpp @@ -171,7 +171,7 @@ void ConfigType::ValidateDictionary(const Dictionary::Ptr& dictionary, else if (overallResult == ValidationInvalidType) ConfigCompilerContext::GetContext()->AddError(false, "Invalid type for attribute: " + LocationToString(locations)); - if (subRuleLists.size() > 0 && value.IsObjectType()) + if (!subRuleLists.empty() && value.IsObjectType()) ValidateDictionary(value, subRuleLists, locations); locations.pop_back(); diff --git a/lib/icinga/externalcommandprocessor.cpp b/lib/icinga/externalcommandprocessor.cpp index c07494e36..c908c5ded 100644 --- a/lib/icinga/externalcommandprocessor.cpp +++ b/lib/icinga/externalcommandprocessor.cpp @@ -51,7 +51,7 @@ void ExternalCommandProcessor::Execute(const String& line) vector argv = args.Split(is_any_of(";")); - if (argv.size() == 0) + if (argv.empty()) BOOST_THROW_EXCEPTION(invalid_argument("Missing arguments in command: " + line)); vector argvExtra(argv.begin() + 1, argv.end()); diff --git a/lib/icinga/notification.cpp b/lib/icinga/notification.cpp index cd4d55779..5e18cea1a 100644 --- a/lib/icinga/notification.cpp +++ b/lib/icinga/notification.cpp @@ -209,7 +209,7 @@ void Notification::BeginExecuteNotification(NotificationType type) BeginExecuteNotificationHelper(macros, type, user); } - if (allUsers.size() == 0) { + if (allUsers.empty()) { /* Send a notification even if there are no users specified. */ BeginExecuteNotificationHelper(macros, type, User::Ptr()); } diff --git a/lib/icinga/service-comment.cpp b/lib/icinga/service-comment.cpp index f956954e7..823b850ec 100644 --- a/lib/icinga/service-comment.cpp +++ b/lib/icinga/service-comment.cpp @@ -277,7 +277,7 @@ void Service::RemoveExpiredComments(void) } } - if (expiredComments.size() > 0) { + if (!expiredComments.empty()) { BOOST_FOREACH(const String& id, expiredComments) { comments->Remove(id); } diff --git a/lib/icinga/service-downtime.cpp b/lib/icinga/service-downtime.cpp index 96b580198..3d0433682 100644 --- a/lib/icinga/service-downtime.cpp +++ b/lib/icinga/service-downtime.cpp @@ -350,7 +350,7 @@ void Service::RemoveExpiredDowntimes(void) } } - if (expiredDowntimes.size() > 0) { + if (!expiredDowntimes.empty()) { BOOST_FOREACH(const String& id, expiredDowntimes) { downtimes->Remove(id); } diff --git a/lib/icinga/service-notification.cpp b/lib/icinga/service-notification.cpp index dc55f4e53..23faac1e3 100644 --- a/lib/icinga/service-notification.cpp +++ b/lib/icinga/service-notification.cpp @@ -63,7 +63,7 @@ void Service::SendNotifications(NotificationType type) set notifications = GetNotifications(); - if (notifications.size() == 0) + if (notifications.empty()) Logger::Write(LogInformation, "icinga", "Service '" + GetName() + "' does not have any notifications."); BOOST_FOREACH(const Notification::Ptr& notification, notifications) { diff --git a/lib/remoting/endpointmanager.cpp b/lib/remoting/endpointmanager.cpp index 41899ea60..fc09b1013 100644 --- a/lib/remoting/endpointmanager.cpp +++ b/lib/remoting/endpointmanager.cpp @@ -397,7 +397,7 @@ void EndpointManager::RequestTimerHandler(void) ObjectLock olock(this); map::iterator it; - for (it = m_Requests.begin(); it != m_Requests.end(); it++) { + for (it = m_Requests.begin(); it != m_Requests.end(); ++it) { if (it->second.HasTimedOut()) { it->second.Callback(GetSelf(), Endpoint::Ptr(), it->second.Request, ResponseMessage(), true);