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"
<< "\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);

View File

@ -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<Endpoint::Ptr>::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<Dictionary>();

View File

@ -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<Dictionary>())
continue;

View File

@ -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<Dictionary>())
if (!subRuleLists.empty() && value.IsObjectType<Dictionary>())
ValidateDictionary(value, subRuleLists, locations);
locations.pop_back();

View File

@ -51,7 +51,7 @@ void ExternalCommandProcessor::Execute(const String& line)
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));
vector<String> argvExtra(argv.begin() + 1, argv.end());

View File

@ -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());
}

View File

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

View File

@ -63,7 +63,7 @@ void Service::SendNotifications(NotificationType type)
set<Notification::Ptr> 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) {

View File

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