Fix cppcheck warnings.

This commit is contained in:
Gunnar Beutner 2013-03-06 15:41:13 +01:00
parent 6f7b553acd
commit 659fcf8fa3
10 changed files with 12 additions and 29 deletions

View File

@ -270,22 +270,9 @@ void CompatComponent::DumpHostStatus(ostream& fp, const Host::Ptr& host)
fp << "hoststatus {" << "\n" fp << "hoststatus {" << "\n"
<< "\t" << "host_name=" << host->GetName() << "\n"; << "\t" << "host_name=" << host->GetName() << "\n";
ServiceState hcState = StateOK;
Service::Ptr hc = host->GetHostCheckService(); Service::Ptr hc = host->GetHostCheckService();
ObjectLock olock(hc); 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) if (hc)
DumpServiceStatusAttrs(fp, hc, CompatTypeHost); DumpServiceStatusAttrs(fp, hc, CompatTypeHost);

View File

@ -104,8 +104,6 @@ void DelegationComponent::DelegationTimerHandler(void)
histogram[endpoint]++; histogram[endpoint]++;
} }
//std::random_shuffle(services.begin(), services.end());
int delegated = 0; int delegated = 0;
/* re-assign services */ /* re-assign services */
@ -119,9 +117,7 @@ void DelegationComponent::DelegationTimerHandler(void)
int avg_services = 0, overflow_tolerance = 0; int avg_services = 0, overflow_tolerance = 0;
vector<Endpoint::Ptr>::iterator cit; vector<Endpoint::Ptr>::iterator cit;
if (candidates.size() > 0) { if (!candidates.empty()) {
//std::random_shuffle(candidates.begin(), candidates.end());
stringstream msgbuf; stringstream msgbuf;
msgbuf << "Service: " << service->GetName() << ", candidates: " << candidates.size(); msgbuf << "Service: " << service->GetName() << ", candidates: " << candidates.size();
Logger::Write(LogDebug, "delegation", msgbuf.str()); Logger::Write(LogDebug, "delegation", msgbuf.str());
@ -176,7 +172,7 @@ void DelegationComponent::DelegationTimerHandler(void)
break; break;
} }
if (candidates.size() == 0) { if (candidates.empty()) {
if (service->GetState() != StateUncheckable && service->GetEnableActiveChecks()) { if (service->GetState() != StateUncheckable && service->GetEnableActiveChecks()) {
Dictionary::Ptr cr = boost::make_shared<Dictionary>(); Dictionary::Ptr cr = boost::make_shared<Dictionary>();

View File

@ -79,7 +79,7 @@ Dictionary::Ptr DynamicObject::BuildUpdate(double sinceTx, int attributeTypes) c
{ {
boost::mutex::scoped_lock lock(m_AttributeMutex); 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) if (it->second.GetType() == Attribute_Transient)
continue; continue;
@ -132,7 +132,7 @@ void DynamicObject::ApplyUpdate(const Dictionary::Ptr& serializedUpdate,
if (configTx > m_ConfigTx) { if (configTx > m_ConfigTx) {
DynamicObject::AttributeIterator at; 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) if ((at->second.GetType() & Attribute_Config) == 0)
continue; continue;
@ -149,7 +149,7 @@ void DynamicObject::ApplyUpdate(const Dictionary::Ptr& serializedUpdate,
ObjectLock alock(attrs); ObjectLock alock(attrs);
Dictionary::Iterator it; Dictionary::Iterator it;
for (it = attrs->Begin(); it != attrs->End(); it++) { for (it = attrs->Begin(); it != attrs->End(); ++it) {
if (!it->second.IsObjectType<Dictionary>()) if (!it->second.IsObjectType<Dictionary>())
continue; continue;

View File

@ -171,7 +171,7 @@ void ConfigType::ValidateDictionary(const Dictionary::Ptr& dictionary,
else if (overallResult == ValidationInvalidType) else if (overallResult == ValidationInvalidType)
ConfigCompilerContext::GetContext()->AddError(false, "Invalid type for attribute: " + LocationToString(locations)); ConfigCompilerContext::GetContext()->AddError(false, "Invalid type for attribute: " + LocationToString(locations));
if (subRuleLists.size() > 0 && value.IsObjectType<Dictionary>()) if (!subRuleLists.empty() && value.IsObjectType<Dictionary>())
ValidateDictionary(value, subRuleLists, locations); ValidateDictionary(value, subRuleLists, locations);
locations.pop_back(); locations.pop_back();

View File

@ -51,7 +51,7 @@ void ExternalCommandProcessor::Execute(const String& line)
vector<String> argv = args.Split(is_any_of(";")); vector<String> argv = args.Split(is_any_of(";"));
if (argv.size() == 0) if (argv.empty())
BOOST_THROW_EXCEPTION(invalid_argument("Missing arguments in command: " + line)); BOOST_THROW_EXCEPTION(invalid_argument("Missing arguments in command: " + line));
vector<String> argvExtra(argv.begin() + 1, argv.end()); vector<String> argvExtra(argv.begin() + 1, argv.end());

View File

@ -209,7 +209,7 @@ void Notification::BeginExecuteNotification(NotificationType type)
BeginExecuteNotificationHelper(macros, type, user); BeginExecuteNotificationHelper(macros, type, user);
} }
if (allUsers.size() == 0) { if (allUsers.empty()) {
/* Send a notification even if there are no users specified. */ /* Send a notification even if there are no users specified. */
BeginExecuteNotificationHelper(macros, type, User::Ptr()); BeginExecuteNotificationHelper(macros, type, User::Ptr());
} }

View File

@ -277,7 +277,7 @@ void Service::RemoveExpiredComments(void)
} }
} }
if (expiredComments.size() > 0) { if (!expiredComments.empty()) {
BOOST_FOREACH(const String& id, expiredComments) { BOOST_FOREACH(const String& id, expiredComments) {
comments->Remove(id); comments->Remove(id);
} }

View File

@ -350,7 +350,7 @@ void Service::RemoveExpiredDowntimes(void)
} }
} }
if (expiredDowntimes.size() > 0) { if (!expiredDowntimes.empty()) {
BOOST_FOREACH(const String& id, expiredDowntimes) { BOOST_FOREACH(const String& id, expiredDowntimes) {
downtimes->Remove(id); downtimes->Remove(id);
} }

View File

@ -63,7 +63,7 @@ void Service::SendNotifications(NotificationType type)
set<Notification::Ptr> notifications = GetNotifications(); set<Notification::Ptr> notifications = GetNotifications();
if (notifications.size() == 0) if (notifications.empty())
Logger::Write(LogInformation, "icinga", "Service '" + GetName() + "' does not have any notifications."); Logger::Write(LogInformation, "icinga", "Service '" + GetName() + "' does not have any notifications.");
BOOST_FOREACH(const Notification::Ptr& notification, notifications) { BOOST_FOREACH(const Notification::Ptr& notification, notifications) {

View File

@ -397,7 +397,7 @@ void EndpointManager::RequestTimerHandler(void)
ObjectLock olock(this); ObjectLock olock(this);
map<String, PendingRequest>::iterator it; map<String, PendingRequest>::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()) { if (it->second.HasTimedOut()) {
it->second.Callback(GetSelf(), Endpoint::Ptr(), it->second.Callback(GetSelf(), Endpoint::Ptr(),
it->second.Request, ResponseMessage(), true); it->second.Request, ResponseMessage(), true);