[SSM] Fix static analysis tool issues and 64bit build support
authorjk13 <jihyeok13.kim@samsung.com>
Thu, 18 Dec 2014 06:24:30 +0000 (15:24 +0900)
committerjk13 <jihyeok13.kim@samsung.com>
Thu, 18 Dec 2014 06:24:30 +0000 (15:24 +0900)
1. Fix code that detected by prevent(static analysis)
2. Fix code to support 64bit build

Change-Id: I21ded9571d2b4fc257991a534171e1931e6ba344
Signed-off-by: jk13 <jihyeok13.kim@samsung.com>
service/soft-sensor-manager/SSMCore/src/Common/ObjectManager.h
service/soft-sensor-manager/SSMCore/src/QueryProcessor/ContextModel.cpp
service/soft-sensor-manager/SSMCore/src/QueryProcessor/EvaluationEngine.cpp
service/soft-sensor-manager/SSMCore/src/QueryProcessor/PropagationEngine.cpp
service/soft-sensor-manager/SSMCore/src/QueryProcessor/QueryEngine.cpp
service/soft-sensor-manager/SSMCore/src/SSMInterface/SSMResourceServer.cpp
service/soft-sensor-manager/SSMCore/src/SensorProcessor/ContextExecutor.cpp
service/soft-sensor-manager/SSMCore/src/SensorProcessor/ContextRepository.cpp
service/soft-sensor-manager/SampleApp/linux/THSensorApp/include/ThingResourceServer.h
service/soft-sensor-manager/SampleApp/linux/THSensorApp1/include/ThingResourceServer1.h

index b2517e7..373734e 100644 (file)
@@ -56,11 +56,17 @@ const OID OID_IBase = {0x3b465976, 0x6486, 0x4c1f, {0x84, 0xb9, 0xeb, 0x80, 0x79
 */
 inline int IsEqualOID(const OID &oid1, const OID &oid2)
 {
-    return (
-               ((unsigned long *) &oid1)[0] == ((unsigned long *) &oid2)[0] &&
-               ((unsigned long *) &oid1)[1] == ((unsigned long *) &oid2)[1] &&
-               ((unsigned long *) &oid1)[2] == ((unsigned long *) &oid2)[2] &&
-               ((unsigned long *) &oid1)[3] == ((unsigned long *) &oid2)[3]);
+    return (( oid1.data1 ==  oid2.data1) &&
+            ( oid1.data2 ==  oid2.data2) &&
+            ( oid1.data3 ==  oid2.data3) &&
+            ( oid1.data4[0] ==  oid2.data4[0]) &&
+            ( oid1.data4[1] ==  oid2.data4[1]) &&
+            ( oid1.data4[2] ==  oid2.data4[2]) &&
+            ( oid1.data4[3] ==  oid2.data4[3]) &&
+            ( oid1.data4[4] ==  oid2.data4[4]) &&
+            ( oid1.data4[5] ==  oid2.data4[5]) &&
+            ( oid1.data4[6] ==  oid2.data4[6]) &&
+            ( oid1.data4[7] ==  oid2.data4[7]));
 }
 
 /**
index 93502c2..20029b1 100644 (file)
@@ -92,7 +92,7 @@ CLEANUP:
 void CContextModel::registerSSMResource(IN ActivationType activationType, IN int targetDeviceDataId,
                                         IN ISSMResource *pSSMResource)
 {
-    int     *pData = NULL;
+    intptr_t     *pData = NULL;
 
     m_mtxActivationCount.lock();
     switch (activationType)
@@ -100,9 +100,9 @@ void CContextModel::registerSSMResource(IN ActivationType activationType, IN int
         case ACTIVATION_TYPE_SUBSCRIBE:
             if (m_mapSubscribedDevice.find(targetDeviceDataId) == m_mapSubscribedDevice.end())
             {
-                pData = new int[2];
+                pData = new intptr_t  [2];
                 pData[0] = STATUS_ACTIVATE;
-                pData[1] = (int)pSSMResource;
+                pData[1] = reinterpret_cast<intptr_t>(pSSMResource);
                 m_pTasker->addTask(this, (void *)pData);
                 m_mapSubscribedDevice[targetDeviceDataId] = 1;
             }
@@ -117,9 +117,9 @@ void CContextModel::registerSSMResource(IN ActivationType activationType, IN int
             {
                 if (m_mapGetDevice.find(targetDeviceDataId) == m_mapGetDevice.end())
                 {
-                    pData = new int[2];
+                    pData = new intptr_t[2];
                     pData[0] = STATUS_START_READ_VALUE;
-                    pData[1] = (int)pSSMResource;
+                    pData[1] = reinterpret_cast<intptr_t>(pSSMResource);
                     m_pTasker->addTask(this, (void *)pData);
                     m_mapGetDevice[targetDeviceDataId] = 1;
                 }
@@ -139,7 +139,7 @@ void CContextModel::registerSSMResource(IN ActivationType activationType, IN int
 void CContextModel::unregisterSSMResource(IN ActivationType activationType,
         IN int targetDeviceDataId, IN ISSMResource *pSSMResource)
 {
-    int     *pData = NULL;
+    intptr_t     *pData = NULL;
 
     m_mtxActivationCount.lock();
     switch (activationType)
@@ -149,9 +149,9 @@ void CContextModel::unregisterSSMResource(IN ActivationType activationType,
             {
                 if (--m_mapSubscribedDevice[targetDeviceDataId] == 0)
                 {
-                    pData = new int[2];
+                    pData = new intptr_t [2];
                     pData[0] = STATUS_DEACTIVATE;
-                    pData[1] = (int)pSSMResource;
+                    pData[1] = reinterpret_cast<intptr_t>(pSSMResource);
                     m_pTasker->addTask(this, (void *)pData);
                     m_mapSubscribedDevice.erase(targetDeviceDataId);
                 }
@@ -163,9 +163,9 @@ void CContextModel::unregisterSSMResource(IN ActivationType activationType,
             {
                 if (--m_mapGetDevice[targetDeviceDataId] == 0)
                 {
-                    pData = new int[2];
+                    pData = new intptr_t [2];
                     pData[0] = STATUS_STOP_READ_VALUE;
-                    pData[1] = (int)pSSMResource;
+                    pData[1] = reinterpret_cast<intptr_t>(pSSMResource);
                     m_pTasker->addTask(this, (void *)pData);
                 }
             }
@@ -213,7 +213,7 @@ SSMRESULT CContextModel::registerContextModelEvent(IN IContextModelEvent *pConte
 
 void CContextModel::onExecute(IN void *pArg)
 {
-    int *pData = (int *)pArg;
+    intptr_t *pData = (intptr_t *)pArg;
 
     if (m_pContextModelEvent)
     {
@@ -223,7 +223,7 @@ void CContextModel::onExecute(IN void *pArg)
 
 void CContextModel::onTerminate(IN void *pArg)
 {
-    int *pData = (int *)pArg;
+    intptr_t *pData = (intptr_t *)pArg;
     SAFE_ARRAY_DELETE(pData);
 }
 
index 55238ba..1e102c2 100644 (file)
@@ -83,7 +83,7 @@ void CEvaluationEngine::onSQLTrigger(IN sqlite3_context *context, IN int argc,
 void CEvaluationEngine::onExecute(IN void *pArg)
 {
     std::map<int, IEvaluationEngineEvent *>::iterator itor;
-    int     *pData = (int *)pArg;
+    intptr_t *pData = (intptr_t *)pArg;
 
     m_mtxTriggerId.lock();
     itor = m_mapTriggers.find(pData[0]);
@@ -97,13 +97,13 @@ void CEvaluationEngine::onExecute(IN void *pArg)
 
 void CEvaluationEngine::onTerminate(IN void *pArg)
 {
-    int *pData = (int *)pArg;
+    intptr_t *pData = (intptr_t *)pArg;
     SAFE_ARRAY_DELETE(pData);
 }
 
 SSMRESULT CEvaluationEngine::onWatcherTriggered(IN int triggerId, IN int dataId)
 {
-    int     *pData = new int[2];
+    intptr_t     *pData = new intptr_t[2];
     pData[0] = triggerId;
     pData[1] = dataId;
     m_pTasker->addTask(this, (void *)pData);
@@ -912,14 +912,14 @@ SSMRESULT CEvaluationEngine::watchModelData(IN int modelId, IN ModelConditionVec
     sstream << "CREATE TRIGGER WatchInsertModel" << m_iTriggerId << " AFTER INSERT ON [ModelData" <<
             modelId << "] WHEN ";
     sstream << sstreamCondition.str().c_str() << " BEGIN SELECT OnSQLTrigger(" <<
-            (int)this << ", " << m_iTriggerId << ", NEW.dataId); END;" << std::ends;
+            reinterpret_cast<intptr_t>(this) << ", " << m_iTriggerId << ", NEW.dataId); END;" << std::ends;
     SSM_CLEANUP_ASSERT(executeSQL_NoReturn(sstream.str()));
     sstream.str("");
 
     sstream << "CREATE TRIGGER WatchUpdateModel" << m_iTriggerId << " AFTER UPDATE ON [ModelData" <<
             modelId << "] WHEN ";
     sstream << sstreamCondition.str().c_str() << " BEGIN SELECT OnSQLTrigger(" <<
-            (int)this << ", " << m_iTriggerId << ", NEW.dataId); END;" << std::ends;
+            reinterpret_cast<intptr_t>(this) << ", " << m_iTriggerId << ", NEW.dataId); END;" << std::ends;
     SSM_CLEANUP_ASSERT(executeSQL_NoReturn(sstream.str()));
 
     m_mtxTriggerId.lock();
index 58d2df4..91423e6 100644 (file)
@@ -364,7 +364,7 @@ void CPropagationEngine::onExecute(IN void *pArg)
 {
     SSMRESULT res = SSM_E_FAIL;
 
-    int         *pMessage = (int *)pArg;
+    intptr_t         *pMessage = (intptr_t *)pArg;
 
     RESOURCE_EVENT_TYPE eventType = (RESOURCE_EVENT_TYPE)pMessage[0];
     ISSMResource            *pResource = (ISSMResource *)pMessage[1];
@@ -395,7 +395,7 @@ CLEANUP:
 
 void CPropagationEngine::onTerminate(IN void *pArg)
 {
-    int         *pMessage = (int *)pArg;
+    intptr_t         *pMessage = (intptr_t *)pArg;
 
     delete[] pMessage;
 }
@@ -403,10 +403,10 @@ void CPropagationEngine::onTerminate(IN void *pArg)
 int CPropagationEngine::onResourceEvent(IN RESOURCE_EVENT_TYPE eventType,
                                         IN ISSMResource *pSSMResource, IN std::string info)
 {
-    int         *pMessage = new int[2];
+    intptr_t          *pMessage = new intptr_t [2];
 
     pMessage[0] = eventType;
-    pMessage[1] = (int)pSSMResource;
+    pMessage[1] = reinterpret_cast<intptr_t>(pSSMResource);
     return (int)m_pTasker->addTask(this, (void *)pMessage);
 }
 
index 62d8eca..100de71 100644 (file)
@@ -71,7 +71,7 @@ SSMRESULT CQueryEngine::processQueryResult(IN int userTriggerId,
     IContextModel           *temp_contextmodel = NULL;
     IContextModel           *temp_contextmodel2 = NULL;
 
-    int             *pData = NULL;
+    intptr_t             *pData = NULL;
 
     CDataReader *pDataReader = NULL;
 
@@ -160,10 +160,10 @@ SSMRESULT CQueryEngine::processQueryResult(IN int userTriggerId,
 
         SSM_CLEANUP_ASSERT(pDataReader->addModelData((result_model_data_id)[i].modelName, &modelDataSet));
     }
-    pData = new int[3];
+    pData = new intptr_t [3];
     pData[0] = EVENT_TYPE_OUTER;
     pData[1] = userTriggerId;
-    pData[2] = (int)pDataReader;
+    pData[2] = reinterpret_cast<intptr_t>(pDataReader);
 
     m_pTasker->addTask(this, (void *)pData);
 
@@ -234,7 +234,7 @@ CLEANUP:
 
 void CQueryEngine::onExecute(void *pArg)
 {
-    int *pData = (int *)pArg;
+    intptr_t *pData = (intptr_t *)pArg;
 
     switch (pData[0])
     {
@@ -256,7 +256,7 @@ void CQueryEngine::onExecute(void *pArg)
 
 void CQueryEngine::onTerminate(void *pArg)
 {
-    int *pData = (int *)pArg;
+    intptr_t *pData = (intptr_t *)pArg;
     std::vector<result_model>   *pResult = NULL;
     CDataReader                 *pDataReader = NULL;
 
@@ -329,10 +329,10 @@ SSMRESULT CQueryEngine::executeContextQuery(IN std::string contextQuery, OUT int
         if (validateQueryResult(pConditionedQueryResult, pResult) == SSM_S_OK)
         {
             //We have valid data, let's deliver to application.
-            int *pData = new int[3];
+            intptr_t  *pData = new intptr_t [3];
             pData[0] = EVENT_TYPE_INNER;
             pData[1] = m_cqid;
-            pData[2] = (int)pResult;
+            pData[2] = reinterpret_cast<intptr_t>(pResult);
 
             m_pTasker->addTask(this, (void *)pData);
         }
index 8fe3bb2..de15320 100644 (file)
@@ -251,7 +251,7 @@ OCEntityHandlerResult SSMResourceServer::entityHandler(std::shared_ptr< OCResour
                         goto CLEANUP;
                     }
 
-                    sstream << (int) pQueryEngine;
+                    sstream << reinterpret_cast<intptr_t>(pQueryEngine);
 
                     // Register QueryEngineEvent
                     queryEngineEvent = new CQueryEngineEvent(sstream.str(), m_hSSMResource);
index 2fbcd84..668421f 100644 (file)
@@ -150,7 +150,7 @@ void CContextExecutor::registerContext(TypeofEvent callType, ISSMResource *pSSMR
 
 void CContextExecutor::onExecute(IN void *pArg)
 {
-    int         *pMessage = (int *)pArg;
+    intptr_t         *pMessage = (intptr_t *)pArg;
 
     RESOURCE_EVENT_TYPE     eventType = (RESOURCE_EVENT_TYPE)pMessage[0];
     ISSMResource            *pResource = (ISSMResource *)pMessage[1];
@@ -191,7 +191,7 @@ void CContextExecutor::onExecute(IN void *pArg)
 
 void CContextExecutor::onTerminate(IN void *pArg)
 {
-    int         *pMessage = (int *)pArg;
+    intptr_t         *pMessage = (intptr_t *)pArg;
 
     delete[] pMessage;
 }
@@ -199,10 +199,10 @@ void CContextExecutor::onTerminate(IN void *pArg)
 int CContextExecutor::onResourceEvent(RESOURCE_EVENT_TYPE eventType, ISSMResource *pSSMResource,
                                       std::string info)
 {
-    int         *pMessage = new int[2];
+    intptr_t          *pMessage = new intptr_t [2];
 
     pMessage[0] = eventType;
-    pMessage[1] = (int)pSSMResource;
+    pMessage[1] = reinterpret_cast<intptr_t>(pSSMResource);
     return (int)m_pTasker->addTask(this, (void *)pMessage);
 }
 
index c17f703..d4b133d 100644 (file)
@@ -322,55 +322,46 @@ SSMRESULT CContextRepository::loadSoftSensor(std::string softSensorName, ICtxDel
     InitContext InitializeContextFunction = NULL;
 
     // load dll(so)
-    res = SSM_E_FAIL;
-    for (unsigned int i = 1; i <= SSM_MODEL_RETRY; ++i)
-    {
-        sstream.str("");
 
 #ifdef WIN32
-        sstream << m_pathSoftSensors << softSensorName.c_str() << ".dll" << std::ends;
+    sstream << m_pathSoftSensors << softSensorName.c_str() << ".dll" << std::ends;
 
-        HINSTANCE hModule = NULL;
-        hModule = LoadLibraryA(sstream.str().c_str());
+    HINSTANCE hModule = NULL;
+    hModule = LoadLibraryA(sstream.str().c_str());
 
-        if (hModule != NULL)
-        {
-            InitializeContextFunction = (InitContext)GetProcAddress(hModule, "InitializeContext");
-        }
+    if (hModule != NULL)
+    {
+        InitializeContextFunction = (InitContext)GetProcAddress(hModule, "InitializeContext");
+    }
 #else
-        //sstream << "/data/data/com.example.javaproject/lib/lib" << modelName <<".so" << std::ends;
-        sstream << m_pathSoftSensors << "lib" << softSensorName.c_str() << ".so" << std::ends;
+    //sstream << "/data/data/com.example.javaproject/lib/lib" << modelName <<".so" << std::ends;
+    sstream << m_pathSoftSensors << "lib" << softSensorName.c_str() << ".so" << std::ends;
 
-        void *hModule = NULL;
-        hModule = dlopen(sstream.str().c_str(), RTLD_LOCAL | RTLD_LAZY);
+    void *hModule = NULL;
+    hModule = dlopen(sstream.str().c_str(), RTLD_LOCAL | RTLD_LAZY);
 
-        if (hModule != NULL)
-        {
-            InitializeContextFunction = (InitContext)dlsym(hModule, "InitializeContext");
-        }
+    if (hModule != NULL)
+    {
+        InitializeContextFunction = (InitContext)dlsym(hModule, "InitializeContext");
+    }
 #endif
-        if (hModule == NULL)
-        {
-            //load library failed. raise error
-            SSM_CLEANUP_ASSERT(SSM_E_FAIL);
-            //InitializeContextFunction = NULL;
-            //continue;
-        }
-
-        if (InitializeContextFunction != NULL)
-        {
-            InitializeContextFunction(pDelegate);
-            *hSoftSensor = hModule;
-            res = SSM_S_OK;
-        }
-        else
-        {
-            //Unload module and return error
-            SSM_CLEANUP_ASSERT(unloadSoftSensor(hModule));
-            SSM_CLEANUP_ASSERT(SSM_E_FAIL);
-        }
+    if (hModule == NULL)
+    {
+        //load library failed. raise error
+        SSM_CLEANUP_ASSERT(SSM_E_FAIL);
+    }
 
-        break;
+    if (InitializeContextFunction != NULL)
+    {
+        InitializeContextFunction(pDelegate);
+        *hSoftSensor = hModule;
+        res = SSM_S_OK;
+    }
+    else
+    {
+        //Unload module and return error
+        SSM_CLEANUP_ASSERT(unloadSoftSensor(hModule));
+        SSM_CLEANUP_ASSERT(SSM_E_FAIL);
     }
 
 CLEANUP:
@@ -420,6 +411,8 @@ SSMRESULT CContextRepository::GetCurrentPath(std::string *path)
         SSM_CLEANUP_ASSERT(SSM_E_FAIL);
     }
 
+    buffer[length] = '\0';
+
     strPath = strrchr(buffer, '/');
 
     if (strPath == NULL)
index d8b5dc8..712a83b 100644 (file)
@@ -60,7 +60,7 @@ class TemphumidResource
     public:
         /// Constructor
         TemphumidResource() :
-            m_humid(0), m_temp(0)
+            m_humid(0), m_temp(0), m_resourceHandle(0)
         {
             m_resourceUri = "/Thing_TempHumSensor";
             m_resourceTypes.push_back(COAP_TYPE_NAME);
index b32b589..c854f69 100644 (file)
@@ -60,7 +60,7 @@ class TemphumidResource
     public:
         /// Constructor
         TemphumidResource() :
-            m_humid(0), m_temp(0)
+            m_humid(0), m_temp(0), m_resourceHandle(0)
         {
             m_resourceUri = "/Thing_TempHumSensor1";
             m_resourceTypes.push_back(COAP_TYPE_NAME);