From f8fd71f5bb1ca8c1a37708502d14c58ae592d9d6 Mon Sep 17 00:00:00 2001 From: dev Date: Fri, 22 Mar 2024 12:28:12 -0400 Subject: [PATCH 1/3] VH-1279: Fix sonar reported bugs in MessageRouterBasic.cpp --- src/tmx/TmxCore/src/MessageRouterBasic.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/tmx/TmxCore/src/MessageRouterBasic.cpp b/src/tmx/TmxCore/src/MessageRouterBasic.cpp index ff7b78a5f..4ac9a61d1 100644 --- a/src/tmx/TmxCore/src/MessageRouterBasic.cpp +++ b/src/tmx/TmxCore/src/MessageRouterBasic.cpp @@ -50,11 +50,11 @@ void MessageRouterBasic::broadcastMessage(MessageReceiver *sender, IvpMessage *m //PerformanceTimer timer; - pthread_mutex_lock(&this->mMapLock); pthread_mutex_lock(&this->mActiveBroadcastsLock); - this->mActiveBroadcasts++; + // Volatile type should not be used in compound operations cpp:S6191 + auto val = this->mActiveBroadcasts; + this->mActiveBroadcasts = val + 1; pthread_mutex_unlock(&this->mActiveBroadcastsLock); - pthread_mutex_unlock(&this->mMapLock); int broadcastCount = 0; @@ -107,9 +107,10 @@ void MessageRouterBasic::broadcastMessage(MessageReceiver *sender, IvpMessage *m } } } - + // Volatile type should not be used in compound operations cpp:S6191 pthread_mutex_lock(&this->mActiveBroadcastsLock); - this->mActiveBroadcasts--; + auto val = this->mActiveBroadcasts; + this->mActiveBroadcasts = val - 1; pthread_mutex_unlock(&this->mActiveBroadcastsLock); //LOG_DEBUG("MessageRouterBasic::broadcastMessage for " << msg->subtype << " from "<< sender->pluginName << " Time (ms) "< Date: Mon, 25 Mar 2024 10:07:49 -0400 Subject: [PATCH 2/3] Remove unnecessary volatile keywork --- src/tmx/TmxCore/src/MessageRouterBasic.cpp | 7 +++---- src/tmx/TmxCore/src/MessageRouterBasic.h | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/tmx/TmxCore/src/MessageRouterBasic.cpp b/src/tmx/TmxCore/src/MessageRouterBasic.cpp index 4ac9a61d1..75e0e368f 100644 --- a/src/tmx/TmxCore/src/MessageRouterBasic.cpp +++ b/src/tmx/TmxCore/src/MessageRouterBasic.cpp @@ -52,8 +52,7 @@ void MessageRouterBasic::broadcastMessage(MessageReceiver *sender, IvpMessage *m pthread_mutex_lock(&this->mActiveBroadcastsLock); // Volatile type should not be used in compound operations cpp:S6191 - auto val = this->mActiveBroadcasts; - this->mActiveBroadcasts = val + 1; + this->mActiveBroadcasts++; pthread_mutex_unlock(&this->mActiveBroadcastsLock); int broadcastCount = 0; @@ -107,10 +106,10 @@ void MessageRouterBasic::broadcastMessage(MessageReceiver *sender, IvpMessage *m } } } + // Volatile type should not be used in compound operations cpp:S6191 pthread_mutex_lock(&this->mActiveBroadcastsLock); - auto val = this->mActiveBroadcasts; - this->mActiveBroadcasts = val - 1; + this->mActiveBroadcasts--; pthread_mutex_unlock(&this->mActiveBroadcastsLock); //LOG_DEBUG("MessageRouterBasic::broadcastMessage for " << msg->subtype << " from "<< sender->pluginName << " Time (ms) "< Date: Mon, 25 Mar 2024 10:46:09 -0400 Subject: [PATCH 3/3] Remove comments --- src/tmx/TmxCore/src/MessageRouterBasic.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/tmx/TmxCore/src/MessageRouterBasic.cpp b/src/tmx/TmxCore/src/MessageRouterBasic.cpp index 75e0e368f..9545a57c9 100644 --- a/src/tmx/TmxCore/src/MessageRouterBasic.cpp +++ b/src/tmx/TmxCore/src/MessageRouterBasic.cpp @@ -51,7 +51,6 @@ void MessageRouterBasic::broadcastMessage(MessageReceiver *sender, IvpMessage *m //PerformanceTimer timer; pthread_mutex_lock(&this->mActiveBroadcastsLock); - // Volatile type should not be used in compound operations cpp:S6191 this->mActiveBroadcasts++; pthread_mutex_unlock(&this->mActiveBroadcastsLock); @@ -107,7 +106,6 @@ void MessageRouterBasic::broadcastMessage(MessageReceiver *sender, IvpMessage *m } } - // Volatile type should not be used in compound operations cpp:S6191 pthread_mutex_lock(&this->mActiveBroadcastsLock); this->mActiveBroadcasts--; pthread_mutex_unlock(&this->mActiveBroadcastsLock);