[IOT-2810] [RE] Static Analysis fix for CPP SDK. 65/22865/2
authorJay Sharma <jay.sharma@samsung.com>
Tue, 17 Oct 2017 12:13:53 +0000 (17:43 +0530)
committerAshok Babu Channa <ashok.channa@samsung.com>
Fri, 27 Oct 2017 09:27:43 +0000 (09:27 +0000)
1. Indentation fixes.
2. Uninitialized variable fixes

Bug: https://jira.iotivity.org/browse/IOT-2810
Change-Id: Ibccf1bc11e590cf1b282e77cac3a9901ccf29fa2
Signed-off-by: Jay Sharma <jay.sharma@samsung.com>
21 files changed:
service/resource-encapsulation/examples/linux/NestedAttributesServer.cpp
service/resource-encapsulation/src/common/expiryTimer/src/ExpiryTimer.cpp
service/resource-encapsulation/src/common/expiryTimer/src/ExpiryTimerImpl.cpp
service/resource-encapsulation/src/common/primitiveResource/include/AssertUtils.h
service/resource-encapsulation/src/common/primitiveResource/include/PrimitiveResourceImpl.h
service/resource-encapsulation/src/common/primitiveResource/include/ResourceAttributesConverter.h
service/resource-encapsulation/src/common/primitiveResource/src/RCSResourceAttributes.cpp
service/resource-encapsulation/src/common/primitiveResource/unittests/PrimitiveResourceTest.cpp
service/resource-encapsulation/src/common/utils/include/UnitTestHelper.h
service/resource-encapsulation/src/resourceBroker/src/DevicePresence.cpp
service/resource-encapsulation/src/resourceBroker/src/ResourceBroker.cpp
service/resource-encapsulation/src/resourceBroker/src/ResourcePresence.cpp
service/resource-encapsulation/src/resourceBroker/unittest/ResourcePresenceUnitTest.cpp
service/resource-encapsulation/src/resourceClient/RCSDiscoveryManager.cpp
service/resource-encapsulation/src/resourceClient/RCSDiscoveryManagerImpl.cpp
service/resource-encapsulation/src/resourceClient/RCSRemoteResourceObject.cpp
service/resource-encapsulation/src/serverBuilder/src/InterfaceHandler.cpp
service/resource-encapsulation/src/serverBuilder/src/RCSRequest.cpp
service/resource-encapsulation/src/serverBuilder/src/RCSResourceObject.cpp
service/resource-encapsulation/src/serverBuilder/src/RCSSeparateResponse.cpp
service/resource-encapsulation/src/serverBuilder/unittests/RCSResourceObjectTest.cpp

index 005e0a5..b85ea15 100644 (file)
@@ -324,10 +324,6 @@ int main(void)
     {
         std::cout << "main exception  : " << e.what() << std::endl;
     }
-    catch (...)
-    {
-        std::cout << "main exception  : unknown" << std::endl;
-    }
 
     std::cout << "Stopping the server" << std::endl;
 }
index a3758c6..5e24060 100644 (file)
@@ -46,7 +46,10 @@ namespace OIC
             auto task = ExpiryTimerImpl::getInstance()->post(milliSec, std::move(cb));
             m_tasks[task->getId()] = task;
 
-            if (m_tasks.size() == m_nextSweep) sweep();
+            if (m_tasks.size() == m_nextSweep)
+            {
+                sweep();
+            }
 
             return task->getId();
         }
@@ -55,12 +58,18 @@ namespace OIC
         {
             auto it = m_tasks.find(id);
 
-            if (it == m_tasks.end()) return false;
+            if (it == m_tasks.end())
+            {
+                return false;
+            }
 
             auto task = it->second;
             m_tasks.erase(it);
 
-            if (task->isExecuted()) return false;
+            if (task->isExecuted())
+            {
+                return false;
+            }
 
             return ExpiryTimerImpl::getInstance()->cancel(id);
         }
index c79d1e6..183868e 100644 (file)
@@ -78,7 +78,10 @@ namespace OIC
 
         bool ExpiryTimerImpl::cancel(Id id)
         {
-            if (id == INVALID_ID) return false;
+            if (id == INVALID_ID)
+            {
+                return false;
+            }
 
             std::lock_guard< std::mutex > lock{ m_mutex };
 
@@ -136,7 +139,10 @@ namespace OIC
         {
             for (const auto& info : m_tasks)
             {
-                if (info.second->getId() == id) return true;
+                if (info.second->getId() == id)
+                {
+                    return true;
+                }
             }
             return false;
         }
@@ -156,7 +162,10 @@ namespace OIC
 
         void ExpiryTimerImpl::executeExpired()
         {
-            if (m_tasks.empty()) return;
+            if (m_tasks.empty())
+            {
+                return;
+            }
 
             auto now = std::chrono::system_clock::now().time_since_epoch();
 
@@ -179,7 +188,10 @@ namespace OIC
 
         void ExpiryTimerImpl::run()
         {
-            auto hasTaskOrStop = [this](){ return !m_tasks.empty() || m_stop; };
+            auto hasTaskOrStop = [this]()
+            {
+                return !m_tasks.empty() || m_stop;
+            };
 
             std::unique_lock< std::mutex > lock{ m_mutex };
 
@@ -187,7 +199,10 @@ namespace OIC
             {
                 m_cond.wait(lock, hasTaskOrStop);
 
-                if (m_stop) break;
+                if (m_stop)
+                {
+                    break;
+                }
 
                 m_cond.wait_for(lock, remainingTimeForNext());
 
@@ -204,7 +219,10 @@ namespace OIC
 
         void TimerTask::execute()
         {
-            if (isExecuted()) return;
+            if (isExecuted())
+            {
+                return;
+            }
 
             ExpiryTimerImpl::Id id { m_id };
             m_id = INVALID_ID;
index f556f39..6265dad 100644 (file)
@@ -122,7 +122,10 @@ namespace OIC
         {
             for (auto r : allowed)
             {
-                if (actual == r) return;
+                if (actual == r)
+                {
+                    return;
+                }
             }
 
             throw RCSPlatformException(actual);
@@ -147,7 +150,10 @@ namespace OIC
         invokeOCFuncWithResultExpect(std::initializer_list<OCStackResult> allowed,
                 FUNC&& fn, PARAMS&& ...params)
         {
-            if (Detail::TerminationChecker::isInTermination()) return;
+            if (Detail::TerminationChecker::isInTermination())
+            {
+                return;
+            }
 
             try
             {
@@ -165,7 +171,10 @@ namespace OIC
                 OCStackResult >::type
         invokeOCFunc(FUNC&& fn, PARAMS&& ...params)
         {
-            if (Detail::TerminationChecker::isInTermination()) return;
+            if (Detail::TerminationChecker::isInTermination())
+            {
+                return;
+            }
 
             try
             {
@@ -182,7 +191,10 @@ namespace OIC
                         Detail::NotOCStackResult >::type
         invokeOCFunc(FUNC* fn, PARAMS&& ...params)
         {
-            if (Detail::TerminationChecker::isInTermination()) return;
+            if (Detail::TerminationChecker::isInTermination())
+            {
+                return;
+            }
 
             try
             {
@@ -201,8 +213,10 @@ namespace OIC
                 decltype((obj->*fn)(std::forward< PARAMS >(params)...)), OCStackResult>::
                 type
         {
-            if (Detail::TerminationChecker::isInTermination()) return;
-
+            if (Detail::TerminationChecker::isInTermination())
+            {
+                return;
+            }
             try
             {
                 expectOCStackResultOK(obj->*fn(std::forward< PARAMS >(params)...));
@@ -221,7 +235,10 @@ namespace OIC
                     Detail::NotOCStackResult>::
                     type
         {
-            if (Detail::TerminationChecker::isInTermination()) return;
+            if (Detail::TerminationChecker::isInTermination())
+            {
+                return;
+            }
 
             try
             {
@@ -240,7 +257,10 @@ namespace OIC
                     decltype((obj.get()->*fn)(std::forward< PARAMS >(params)...)), OCStackResult>::
                     type
         {
-            if (Detail::TerminationChecker::isInTermination()) return;
+            if (Detail::TerminationChecker::isInTermination())
+            {
+                return;
+            }
 
             try
             {
@@ -260,7 +280,10 @@ namespace OIC
                    Detail::NotOCStackResult>::
                    type
         {
-            if (Detail::TerminationChecker::isInTermination()) return { };
+            if (Detail::TerminationChecker::isInTermination())
+            {
+                return { };
+            }
 
             try
             {
index 778a62a..bc13112 100644 (file)
@@ -50,7 +50,10 @@ namespace OIC
             {
                 auto checkedRes = resource.lock();
 
-                if (!checkedRes) return;
+                if (!checkedRes)
+                {
+                    return;
+                }
 
                 cb(std::forward< ARGS >(args)...);
             }
index 10f59e0..0fb93ef 100644 (file)
@@ -114,7 +114,8 @@ namespace OIC
                 void insertItem(Detail::Int2Type< DEPTH >,
                         const OC::OCRepresentation::AttributeItem& item)
                 {
-                    switch (item.base_type()) {
+                    switch (item.base_type())
+                    {
                         case OC::AttributeType::Null:
                             return putValue(item.attrname(), nullptr);
 
index ab01604..6666bce 100644 (file)
@@ -63,7 +63,10 @@ namespace
             m_stream << "[";
             for (auto it = v.begin(); it != v.end(); ++it)
             {
-                if (it != v.begin()) m_stream << ", ";
+                if (it != v.begin())
+                {
+                    m_stream << ", ";
+                }
                 (*this)(*it);
             }
             m_stream << "]";
@@ -97,13 +100,17 @@ namespace
             m_stream << "{";
             for (auto it = attrs.begin(); it != attrs.end(); ++it)
             {
-                if (it != attrs.begin()) m_stream << ", ";
+                if (it != attrs.begin())
+                {
+                    m_stream << ", ";
+                }
                 m_stream << "\"" << it->key() << "\" : " << it->value().toString();
             }
             m_stream << "}";
         }
 
-        std::string get() const {
+        std::string get() const
+        {
             return m_stream.str();
         }
 
@@ -456,6 +463,11 @@ namespace OIC
 
         auto RCSResourceAttributes::iterator::operator=(const iterator& rhs) -> iterator&
         {
+            // If it is same object skip assignment
+            if (this == &rhs)
+            {
+                return *this;
+            }
             m_cur = rhs.m_cur;
             return *this;
         }
@@ -524,6 +536,11 @@ namespace OIC
         auto RCSResourceAttributes::const_iterator::operator=(
                 const const_iterator& rhs) -> const_iterator&
         {
+            // If it is same object skip assignment
+            if (this == &rhs)
+            {
+                return *this;
+            }
             m_cur = rhs.m_cur;
             return *this;
         }
index 5a69004..9b81373 100644 (file)
@@ -66,7 +66,8 @@ public:
     FakeOCResource* fakeResource;
 
 protected:
-    void SetUp() {
+    void SetUp()
+    {
         TestWithMock::SetUp();
 
         fakeResource = mocks.Mock< FakeOCResource >();
index 3a9e490..14bfca2 100644 (file)
@@ -32,7 +32,8 @@ public:
 protected:
     virtual ~TestWithMock() noexcept(noexcept(std::declval<Test>().~Test())) {}
 
-    virtual void TearDown() {
+    virtual void TearDown()
+    {
         try
         {
             mocks.VerifyAll();
index 7ebdf3f..cdab171 100644 (file)
@@ -45,7 +45,8 @@ namespace OIC
                 try
                 {
                     presenceSubscriber.unsubscribe();
-                } catch (std::exception & e)
+                }
+                catch (std::exception & e)
                 {
                     OIC_LOG_V(DEBUG,BROKER_TAG,"unsubscribed presence : %s", e.what());
                 }
@@ -66,10 +67,11 @@ namespace OIC
                 OIC_LOG_V(DEBUG, BROKER_TAG, "subscribe Presence");
                 presenceSubscriber
                 = PresenceSubscriber(address, BROKER_TRANSPORT, pSubscribeRequestCB);
-            } catch(RCSPlatformException &e)
+            }
+            catch(RCSPlatformException &e)
             {
                 OIC_LOG_V(DEBUG, BROKER_TAG,
-                        "exception in subscribe Presence %s", e.getReason().c_str());
+                "exception in subscribe Presence %s", e.getReason().c_str());
                 throw;
             }
             presenceTimerHandle
index 970db5f..f858017 100644 (file)
@@ -82,7 +82,8 @@ namespace OIC
                     OIC_LOG_V(DEBUG, BROKER_TAG, "create the ResourcePresence.");
                     presenceItem.reset(new ResourcePresence());
                     presenceItem->initializeResourcePresence(pResource);
-                }catch(RCSPlatformException &e)
+                }
+                catch(RCSPlatformException &e)
                 {
                     throw FailedSubscribePresenceException(e.getReasonCode());
                 }
index c5aba84..da2889c 100644 (file)
@@ -158,7 +158,8 @@ namespace OIC
             return (requesterList!=nullptr)?requesterList->empty():true;
         }
 
-        int ResourcePresence::requesterListSize() const {
+        int ResourcePresence::requesterListSize() const
+        {
             OIC_LOG_V(DEBUG,BROKER_TAG,"requesterListSize().\n");
             return (requesterList!=nullptr)?requesterList->size():0;
         }
index 7dd9927..1147c63 100644 (file)
@@ -117,7 +117,6 @@ TEST_F(ResourcePresenceTest,addBrokerRequester_ReturnNormalValueIfNormalParams)
     id = 1;
     instance->addBrokerRequester(id,cb);
     EXPECT_FALSE(instance->isEmptyRequester());
-
 }
 
 TEST_F(ResourcePresenceTest,removeBrokerRequester_NormalHandlingIfNormalId)
index a44f5d0..9edb290 100644 (file)
@@ -38,7 +38,9 @@ namespace OIC
         void RCSDiscoveryManager::DiscoveryTask::cancel()
         {
             if (isCanceled())
+            {
                 return;
+            }
 
             RCSDiscoveryManagerImpl::getInstance()->cancel(m_id);
             m_id = RCSDiscoveryManagerImpl::INVALID_ID;
index 7db2529..aa60a5e 100644 (file)
@@ -35,9 +35,12 @@ namespace
         return resource->getSid() + resource->getUri();
     }
 
-    void validateTypes(const std::vector< std::string >& resourceTypes) {
-        if (resourceTypes.size() == 1) return;
-
+    void validateTypes(const std::vector< std::string >& resourceTypes)
+    {
+        if (resourceTypes.size() == 1)
+        {
+            return;
+        }
         for (const auto& type : resourceTypes)
         {
             if (type == OIC::Service::RCSDiscoveryManagerImpl::ALL_RESOURCE_TYPE)
@@ -79,9 +82,14 @@ namespace OIC
                 std::lock_guard < std::mutex > lock(m_mutex);
                 auto it = m_discoveryMap.find(discoveryId);
 
-                if (it == m_discoveryMap.end()) return;
-                if (it->second.isKnownResource(resource)) return;
-
+                if (it == m_discoveryMap.end())
+                {
+                    return;
+                }
+                if (it->second.isKnownResource(resource))
+                {
+                    return;
+                }
                 it->second.addKnownResource(resource);
             }
 
@@ -149,7 +157,10 @@ namespace OIC
         void RCSDiscoveryManagerImpl::onPresence(OCStackResult result, const unsigned int /*seq*/,
                 const std::string& address)
         {
-            if (result != OC_STACK_OK && result != OC_STACK_RESOURCE_CREATED) return;
+            if (result != OC_STACK_OK && result != OC_STACK_RESOURCE_CREATED)
+            {
+                return;
+            }
 
             std::lock_guard < std::mutex > lock(m_mutex);
             for (const auto& it : m_discoveryMap)
index 8f1818e..223b06d 100644 (file)
@@ -179,12 +179,13 @@ namespace OIC
         RCSRemoteResourceObject::~RCSRemoteResourceObject()
         {
             SCOPE_LOG_F(DEBUG, TAG);
-
-            try{
+            try
+            {
                 stopCaching();
                 stopMonitoring();
             }
-            catch(std::exception &e){
+            catch(std::exception &e)
+            {
                 OIC_LOG_V(ERROR, TAG, "%s", e.what());
             }
         }
index bf59e69..7a52f8f 100644 (file)
@@ -153,10 +153,16 @@ namespace OIC
                 const std::string& defaultInterfaceName)
         {
             auto it = g_defaultHandlers.find(interfaceName);
-            if (it != g_defaultHandlers.end()) return it->second;
+            if (it != g_defaultHandlers.end())
+            {
+                return it->second;
+            }
 
             it = g_defaultHandlers.find(defaultInterfaceName);
-            if (it != g_defaultHandlers.end()) return it->second;
+            if (it != g_defaultHandlers.end())
+            {
+                return it->second;
+            }
 
             return g_defaultHandlers.find(OIC::Service::BASELINE_INTERFACE)->second;
         }
index 6efc456..8175f9a 100644 (file)
@@ -67,8 +67,10 @@ namespace OIC
 
             auto it = params.find(OC::Key::INTERFACESKEY);
 
-            if (it == params.end()) return "";
-
+            if (it == params.end())
+            {
+                return "";
+            }
             return it->second;
         }
 
index bc22c3d..e817d0c 100644 (file)
@@ -123,7 +123,10 @@ namespace
 
     void insertValue(std::vector<std::string>& container, std::string value)
     {
-        if (value.empty()) return;
+            if (value.empty())
+            {
+                return;
+            }
 
         if (std::find(container.begin(), container.end(), value) == container.end())
         {
@@ -233,12 +236,14 @@ namespace OIC
                     handle, m_uri, m_types[0], m_interfaces[0], entityHandler, m_properties);
 
             std::for_each(m_interfaces.begin() + 1, m_interfaces.end(),
-                    [&handle](const std::string& interfaceName){
+                    [&handle](const std::string& interfaceName)
+            {
                 invokeOCFunc(OC::OCPlatform::bindInterfaceToResource, handle, interfaceName);
             });
 
             std::for_each(m_types.begin() + 1, m_types.end(),
-                    [&handle](const std::string& typeName){
+                    [&handle](const std::string& typeName)
+            {
                 invokeOCFunc(OC::OCPlatform::bindTypeToResource, handle, typeName);
             });
 
@@ -319,7 +324,10 @@ namespace OIC
                 m_resourceAttributes[std::forward< K >(key)] = std::forward< V >(value);
             }
 
-            if (needToNotify) autoNotify(valueUpdated);
+            if (needToNotify)
+            {
+                autoNotify(valueUpdated);
+            }
         }
         void RCSResourceObject::setAttribute(const std::string& key,
                 const RCSResourceAttributes::Value& value)
@@ -366,7 +374,10 @@ namespace OIC
                 }
             }
 
-            if (needToNotify) autoNotify(true);
+            if (needToNotify)
+            {
+                autoNotify(true);
+            }
 
             return erased;
         }
@@ -573,9 +584,16 @@ namespace OIC
         void RCSResourceObject::autoNotify(
                         bool isAttributesChanged, AutoNotifyPolicy autoNotifyPolicy) const
         {
-            if(autoNotifyPolicy == AutoNotifyPolicy::NEVER) return;
+            if(autoNotifyPolicy == AutoNotifyPolicy::NEVER)
+            {
+                return;
+            }
+
             if(autoNotifyPolicy == AutoNotifyPolicy::UPDATED &&
-                    isAttributesChanged == false) return;
+                    isAttributesChanged == false)
+            {
+                return;
+            }
 
             notify();
         }
@@ -586,7 +604,10 @@ namespace OIC
         {
             auto resource = weakRes.lock();
 
-            if (!resource) return OC_EH_ERROR;
+            if (!resource)
+            {
+                return OC_EH_ERROR;
+            }
 
             OIC_LOG(WARNING, LOG_TAG_RE, "entityHandler");
             if (!request)
@@ -655,7 +676,10 @@ namespace OIC
 
             auto response = invokeHandler(attrs, request, m_getRequestHandler);
 
-            if (response.isSeparate()) return OC_EH_SLOW;
+            if (response.isSeparate())
+            {
+                return OC_EH_SLOW;
+            }
 
             return sendResponse(request, response,
                          findInterfaceHandler(request.getInterface()).getGetResponseBuilder());
@@ -707,7 +731,10 @@ namespace OIC
 
             auto response = invokeHandler(attrs, request, m_setRequestHandler);
 
-            if (response.isSeparate()) return OC_EH_SLOW;
+            if (response.isSeparate())
+            {
+                return OC_EH_SLOW;
+            }
 
             autoNotify(applyAcceptanceMethod(response, attrs), m_autoNotifyPolicy);
 
@@ -730,7 +757,10 @@ namespace OIC
         {
             auto it = m_interfaceHandlers.find(interfaceName);
 
-            if (it != m_interfaceHandlers.end()) return it->second;
+            if (it != m_interfaceHandlers.end())
+            {
+                return it->second;
+            }
 
             assert(m_interfaceHandlers.find(m_defaultInterface) != m_interfaceHandlers.end());
 
@@ -798,7 +828,10 @@ namespace OIC
 
         RCSResourceObject::LockGuard::~LockGuard() noexcept(false)
         {
-            if (!std::uncaught_exception() && m_autoNotifyFunc) m_autoNotifyFunc();
+            if (!std::uncaught_exception() && m_autoNotifyFunc)
+            {
+                m_autoNotifyFunc();
+            }
 
             if (m_isOwningLock)
             {
index 8a9e1c0..9ed0c73 100644 (file)
@@ -73,7 +73,10 @@ namespace OIC
                 throw RCSBadRequestException{ "ResourceObject is unspecified(or destroyed)!" };\r
             }\r
 \r
-            if (m_done) throw RCSBadRequestException{ "The response is already set!" };\r
+            if (m_done)\r
+            {\r
+                throw RCSBadRequestException{ "The response is already set!" };\r
+            }\r
 \r
             auto ocRequest = m_request.getOCRequest();\r
             auto response = std::make_shared< OC::OCResourceResponse >();\r
index ad33726..1202c54 100644 (file)
@@ -175,7 +175,8 @@ protected:
                         .Return(OC_STACK_OK);
     }
 
-    virtual void initResourceObject() {
+    virtual void initResourceObject()
+    {
         server->setAutoNotifyPolicy(RCSResourceObject::AutoNotifyPolicy::NEVER);
     }
 };
@@ -280,7 +281,8 @@ protected:
                         .Return(OC_STACK_OK);
     }
 
-    virtual void initResourceObject() {
+    virtual void initResourceObject()
+    {
         // intended blank
     }
 };
@@ -878,7 +880,10 @@ TEST_F(ResourceObjectSynchronizationTest, MultipleAccessToServerResourceWithRequ
             for (int i=0; i<10000; ++i)
 #endif
             {
-                if (i % 5 == 0) handler(createRequest(OC_REST_OBSERVE));
+                if (i % 5 == 0)
+                {
+                    handler(createRequest(OC_REST_OBSERVE));
+                }
                 handler(createRequest((i & 1) ? OC_REST_GET : OC_REST_POST));
             }
         }