update NSAcceptedProviders copy/assign operators 77/25677/3
authorGeorge Nash <george.nash@intel.com>
Wed, 2 May 2018 18:45:10 +0000 (11:45 -0700)
committerRick Bell <richard.s.bell@intel.com>
Thu, 7 Jun 2018 19:44:17 +0000 (19:44 +0000)
This addresses an iterator missmatch error that is reported by
static analysis tool. This changes the code to use the built in
map assignment operator as well as grab locks before copying the
map to prevent the map being modified while the copy is
occuring.

Bug: https://jira.iotivity.org/browse/IOT-1742
Change-Id: Id7d8eeed91d587db7d2b0f8ca6a8d5b3d98f90fe
Signed-off-by: George Nash <george.nash@intel.com>
service/notification/cpp-wrapper/consumer/src/NSAcceptedProviders.cpp

index 1e3edf5..a621916 100644 (file)
@@ -29,14 +29,18 @@ namespace OIC
     {
         NSAcceptedProviders::NSAcceptedProviders(const NSAcceptedProviders &providers)
         {
-            removeProviders();
-            m_providers.insert((providers.getProviders()).begin(), (providers.getProviders()).end());
+            std::lock_guard<std::mutex> lock(m_mutex);
+            std::lock_guard<std::mutex> lock2(providers.m_mutex);
+            m_providers.clear();
+            m_providers = providers.m_providers;
         }
 
         NSAcceptedProviders &NSAcceptedProviders::operator=(const NSAcceptedProviders &providers)
         {
-            removeProviders();
-            this->m_providers.insert((providers.getProviders()).begin(), (providers.getProviders()).end());
+            std::lock_guard<std::mutex> lock(m_mutex);
+            std::lock_guard<std::mutex> lock2(providers.m_mutex);
+            m_providers.clear();
+            m_providers = providers.m_providers;
             return *this;
         }