From 1dd47b5cd0e525d13041e582e09cf7db6f7ba010 Mon Sep 17 00:00:00 2001 From: jk13 Date: Thu, 18 Dec 2014 15:24:30 +0900 Subject: [PATCH] [SSM] Fix static analysis tool issues and 64bit build support 1. Fix code that detected by prevent(static analysis) 2. Fix code to support 64bit build Change-Id: I21ded9571d2b4fc257991a534171e1931e6ba344 Signed-off-by: jk13 --- .../SSMCore/src/Common/ObjectManager.h | 16 ++-- .../src/QueryProcessor/ContextModel.cpp | 24 +++--- .../src/QueryProcessor/EvaluationEngine.cpp | 10 +-- .../src/QueryProcessor/PropagationEngine.cpp | 8 +- .../src/QueryProcessor/QueryEngine.cpp | 14 ++-- .../src/SSMInterface/SSMResourceServer.cpp | 2 +- .../src/SensorProcessor/ContextExecutor.cpp | 8 +- .../src/SensorProcessor/ContextRepository.cpp | 73 +++++++++---------- .../THSensorApp/include/ThingResourceServer.h | 2 +- .../include/ThingResourceServer1.h | 2 +- 10 files changed, 79 insertions(+), 80 deletions(-) diff --git a/service/soft-sensor-manager/SSMCore/src/Common/ObjectManager.h b/service/soft-sensor-manager/SSMCore/src/Common/ObjectManager.h index b2517e72c..373734ed0 100644 --- a/service/soft-sensor-manager/SSMCore/src/Common/ObjectManager.h +++ b/service/soft-sensor-manager/SSMCore/src/Common/ObjectManager.h @@ -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])); } /** diff --git a/service/soft-sensor-manager/SSMCore/src/QueryProcessor/ContextModel.cpp b/service/soft-sensor-manager/SSMCore/src/QueryProcessor/ContextModel.cpp index 93502c2dc..20029b13d 100644 --- a/service/soft-sensor-manager/SSMCore/src/QueryProcessor/ContextModel.cpp +++ b/service/soft-sensor-manager/SSMCore/src/QueryProcessor/ContextModel.cpp @@ -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(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(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(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(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); } diff --git a/service/soft-sensor-manager/SSMCore/src/QueryProcessor/EvaluationEngine.cpp b/service/soft-sensor-manager/SSMCore/src/QueryProcessor/EvaluationEngine.cpp index 55238ba42..1e102c266 100644 --- a/service/soft-sensor-manager/SSMCore/src/QueryProcessor/EvaluationEngine.cpp +++ b/service/soft-sensor-manager/SSMCore/src/QueryProcessor/EvaluationEngine.cpp @@ -83,7 +83,7 @@ void CEvaluationEngine::onSQLTrigger(IN sqlite3_context *context, IN int argc, void CEvaluationEngine::onExecute(IN void *pArg) { std::map::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(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(this) << ", " << m_iTriggerId << ", NEW.dataId); END;" << std::ends; SSM_CLEANUP_ASSERT(executeSQL_NoReturn(sstream.str())); m_mtxTriggerId.lock(); diff --git a/service/soft-sensor-manager/SSMCore/src/QueryProcessor/PropagationEngine.cpp b/service/soft-sensor-manager/SSMCore/src/QueryProcessor/PropagationEngine.cpp index 58d2df454..91423e6e6 100644 --- a/service/soft-sensor-manager/SSMCore/src/QueryProcessor/PropagationEngine.cpp +++ b/service/soft-sensor-manager/SSMCore/src/QueryProcessor/PropagationEngine.cpp @@ -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(pSSMResource); return (int)m_pTasker->addTask(this, (void *)pMessage); } diff --git a/service/soft-sensor-manager/SSMCore/src/QueryProcessor/QueryEngine.cpp b/service/soft-sensor-manager/SSMCore/src/QueryProcessor/QueryEngine.cpp index 62d8ecabd..100de7184 100644 --- a/service/soft-sensor-manager/SSMCore/src/QueryProcessor/QueryEngine.cpp +++ b/service/soft-sensor-manager/SSMCore/src/QueryProcessor/QueryEngine.cpp @@ -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(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 *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(pResult); m_pTasker->addTask(this, (void *)pData); } diff --git a/service/soft-sensor-manager/SSMCore/src/SSMInterface/SSMResourceServer.cpp b/service/soft-sensor-manager/SSMCore/src/SSMInterface/SSMResourceServer.cpp index 8fe3bb22b..de1532051 100644 --- a/service/soft-sensor-manager/SSMCore/src/SSMInterface/SSMResourceServer.cpp +++ b/service/soft-sensor-manager/SSMCore/src/SSMInterface/SSMResourceServer.cpp @@ -251,7 +251,7 @@ OCEntityHandlerResult SSMResourceServer::entityHandler(std::shared_ptr< OCResour goto CLEANUP; } - sstream << (int) pQueryEngine; + sstream << reinterpret_cast(pQueryEngine); // Register QueryEngineEvent queryEngineEvent = new CQueryEngineEvent(sstream.str(), m_hSSMResource); diff --git a/service/soft-sensor-manager/SSMCore/src/SensorProcessor/ContextExecutor.cpp b/service/soft-sensor-manager/SSMCore/src/SensorProcessor/ContextExecutor.cpp index 2fbcd84ee..668421f4e 100644 --- a/service/soft-sensor-manager/SSMCore/src/SensorProcessor/ContextExecutor.cpp +++ b/service/soft-sensor-manager/SSMCore/src/SensorProcessor/ContextExecutor.cpp @@ -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(pSSMResource); return (int)m_pTasker->addTask(this, (void *)pMessage); } diff --git a/service/soft-sensor-manager/SSMCore/src/SensorProcessor/ContextRepository.cpp b/service/soft-sensor-manager/SSMCore/src/SensorProcessor/ContextRepository.cpp index c17f703dd..d4b133dec 100644 --- a/service/soft-sensor-manager/SSMCore/src/SensorProcessor/ContextRepository.cpp +++ b/service/soft-sensor-manager/SSMCore/src/SensorProcessor/ContextRepository.cpp @@ -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) diff --git a/service/soft-sensor-manager/SampleApp/linux/THSensorApp/include/ThingResourceServer.h b/service/soft-sensor-manager/SampleApp/linux/THSensorApp/include/ThingResourceServer.h index d8b5dc81e..712a83bc0 100644 --- a/service/soft-sensor-manager/SampleApp/linux/THSensorApp/include/ThingResourceServer.h +++ b/service/soft-sensor-manager/SampleApp/linux/THSensorApp/include/ThingResourceServer.h @@ -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); diff --git a/service/soft-sensor-manager/SampleApp/linux/THSensorApp1/include/ThingResourceServer1.h b/service/soft-sensor-manager/SampleApp/linux/THSensorApp1/include/ThingResourceServer1.h index b32b589f7..c854f69dd 100644 --- a/service/soft-sensor-manager/SampleApp/linux/THSensorApp1/include/ThingResourceServer1.h +++ b/service/soft-sensor-manager/SampleApp/linux/THSensorApp1/include/ThingResourceServer1.h @@ -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); -- 2.34.1