From 0d5544bc1938a9e4b9be416e424c9265efc53549 Mon Sep 17 00:00:00 2001 From: KIM JungYong Date: Wed, 30 Nov 2016 15:08:29 +0900 Subject: [PATCH] Fix for result of static analysis. In this patch, incorrect coding rule is fixed and resolved warning of static analysis. 1. Uninitialized variables is fixed with initialized. 2. Invalid bracket location is fixed. 3. Incorrect division with zero is prevented. 4. Incorrect referenced pointer is prevented. Change-Id: I715d671241f3d48a1174c49cbe34074b31a50f02 Signed-off-by: KIM JungYong Reviewed-on: https://gerrit.iotivity.org/gerrit/14947 Tested-by: jenkins-iotivity Reviewed-by: Uze Choi --- .../examples/BMISensorBundle/src/BMISensor.cpp | 12 ++++++---- .../HeightSensorApp/src/HeightSensorApp.cpp | 8 +++---- .../WeightSensorApp/src/WeightSensorApp.cpp | 6 ++--- .../examples/ContainerSample.cpp | 4 ++-- .../src/DiscomfortIndexSensor.cpp | 4 ++-- .../src/DiscomfortIndexSensorResource.cpp | 10 +++++--- .../THSensorApp/src/ThingResourceServer.cpp | 8 +++---- .../THSensorApp1/src/ThingResourceServer1.cpp | 8 +++---- .../examples/HueSampleBundle/src/HueConnector.cpp | 8 +++---- service/resource-container/src/Configuration.cpp | 27 ++++++++++++++-------- .../src/ResourceContainerImpl.cpp | 6 ++--- .../unittests/ResourceContainerTest.cpp | 2 +- .../examples/linux/NestedAttributesClient.cpp | 5 ++-- .../examples/linux/NestedAttributesServer.cpp | 2 +- .../examples/linux/SampleResourceClient.cpp | 22 +++++++++--------- .../examples/linux/SampleResourceServer.cpp | 4 ++-- .../examples/linux/SeparateResponseServer.cpp | 2 +- .../expiryTimer/unittests/ExpiryTimerTest.cpp | 4 ++-- .../unittest/ResourceBrokerUnitTest.cpp | 10 ++++---- .../unittest/ResourcePresenceUnitTest.cpp | 2 +- 20 files changed, 84 insertions(+), 70 deletions(-) diff --git a/service/resource-container/examples/BMISensorBundle/src/BMISensor.cpp b/service/resource-container/examples/BMISensorBundle/src/BMISensor.cpp index 6bf73e1..53e96cf 100644 --- a/service/resource-container/examples/BMISensorBundle/src/BMISensor.cpp +++ b/service/resource-container/examples/BMISensorBundle/src/BMISensor.cpp @@ -52,7 +52,7 @@ BMISensor::~BMISensor() int BMISensor::executeBMISensorLogic(std::map *pInputData, std::string *pOutput) { - BMIResult result; + BMIResult result = ERROR; if (pInputData->find("weight") != pInputData->end()) { @@ -81,10 +81,12 @@ int BMISensor::executeBMISensorLogic(std::map *pInputD */ BMIResult BMISensor::makeBMI(void) { - double BMIvalue, timediffsecond; - double dWeight, dHeight; + double BMIvalue = 0.0; + double timediffsecond = 0.0; + double dWeight = 0.0; + double dHeight = 0.0; - int BMIResult; + int BMIResult = 0; if (!m_weight.empty() && !m_height.empty()) { @@ -147,4 +149,4 @@ BMIResult BMISensor::makeBMI(void) } return ERROR; -} \ No newline at end of file +} diff --git a/service/resource-container/examples/BMISensorBundle/src/inputSensors/HeightSensorApp/src/HeightSensorApp.cpp b/service/resource-container/examples/BMISensorBundle/src/inputSensors/HeightSensorApp/src/HeightSensorApp.cpp index 9d43288..2a9dd86 100644 --- a/service/resource-container/examples/BMISensorBundle/src/inputSensors/HeightSensorApp/src/HeightSensorApp.cpp +++ b/service/resource-container/examples/BMISensorBundle/src/inputSensors/HeightSensorApp/src/HeightSensorApp.cpp @@ -52,7 +52,7 @@ OCResourceHandle HeightResource::getHandle() void HeightResource::setResourceRepresentation(OCRepresentation &rep) { - double tempHeight; + double tempHeight = 0.0; rep.getValue("height", tempHeight); @@ -80,7 +80,7 @@ void *TestSensorVal(void *param) bool bFlag = true; int nSleep_time = INTERVAL_FOR_CHECK; - double nHeight; + double nHeight = 0.0; std::cout << "[HeightSensorAPP] ::" << __func__ << " is called." << std::endl; @@ -179,7 +179,7 @@ OCEntityHandlerResult entityHandler(std::shared_ptr< OCResourceRequest > request if (requestFlag & RequestHandlerFlag::ObserverFlag) { - pthread_t threadId; + pthread_t threadId = {}; cout << "\t\trequestFlag : Observer\n"; g_Observation = 1; @@ -220,7 +220,7 @@ int main() OC::OCPlatform::stopPresence(); } - catch (std::exception e) + catch (std::exception & e) { cout << e.what() << endl; } diff --git a/service/resource-container/examples/BMISensorBundle/src/inputSensors/WeightSensorApp/src/WeightSensorApp.cpp b/service/resource-container/examples/BMISensorBundle/src/inputSensors/WeightSensorApp/src/WeightSensorApp.cpp index 07b8096..a52cb70 100644 --- a/service/resource-container/examples/BMISensorBundle/src/inputSensors/WeightSensorApp/src/WeightSensorApp.cpp +++ b/service/resource-container/examples/BMISensorBundle/src/inputSensors/WeightSensorApp/src/WeightSensorApp.cpp @@ -53,7 +53,7 @@ OCResourceHandle WeightResource::getHandle() void WeightResource::setResourceRepresentation(OCRepresentation &rep) { - double tempWeight; + double tempWeight = 0.0; rep.getValue("weight", tempWeight); @@ -80,7 +80,7 @@ void *TestSensorVal(void *param) bool bFlag = true; int nSleep_time = INTERVAL_FOR_CHECK; - double nWeight; + double nWeight = 0.0; std::cout << "[WeightSensorAPP] ::" << __func__ << " is called." << std::endl; @@ -180,7 +180,7 @@ OCEntityHandlerResult entityHandler(std::shared_ptr< OCResourceRequest > request if (requestFlag & RequestHandlerFlag::ObserverFlag) { - pthread_t threadId; + pthread_t threadId = {}; cout << "\t\trequestFlag : Observer\n"; g_Observation = 1; diff --git a/service/resource-container/examples/ContainerSample.cpp b/service/resource-container/examples/ContainerSample.cpp index 4d1c2df..32397b7 100644 --- a/service/resource-container/examples/ContainerSample.cpp +++ b/service/resource-container/examples/ContainerSample.cpp @@ -68,7 +68,7 @@ RCSResourceContainer *g_pResourceContainer = nullptr; void getCurrentPath(std::string *pPath) { - char buffer[MAX_PATH]; + char buffer[MAX_PATH] = {0,}; if (!pPath->empty()) { @@ -95,7 +95,7 @@ void getCurrentPath(std::string *pPath) int processUserInput(int min, int max) { - int input; + int input = 0; std::cin >> input; diff --git a/service/resource-container/examples/DiscomfortIndexSensorBundle/src/DiscomfortIndexSensor.cpp b/service/resource-container/examples/DiscomfortIndexSensorBundle/src/DiscomfortIndexSensor.cpp index 5da9ebb..7fd0309 100644 --- a/service/resource-container/examples/DiscomfortIndexSensorBundle/src/DiscomfortIndexSensor.cpp +++ b/service/resource-container/examples/DiscomfortIndexSensorBundle/src/DiscomfortIndexSensor.cpp @@ -51,7 +51,7 @@ int DiscomfortIndexSensor::executeDISensorLogic(std::mapat("temperature"); m_humidity = pInputData->at("humidity"); @@ -116,4 +116,4 @@ DIResult DiscomfortIndexSensor::makeDiscomfortIndex() m_discomfortIndex = std::to_string(DILevel); return SUCCESS; -} \ No newline at end of file +} diff --git a/service/resource-container/examples/DiscomfortIndexSensorBundle/src/DiscomfortIndexSensorResource.cpp b/service/resource-container/examples/DiscomfortIndexSensorBundle/src/DiscomfortIndexSensorResource.cpp index 2f6f857..e98ce5f 100644 --- a/service/resource-container/examples/DiscomfortIndexSensorBundle/src/DiscomfortIndexSensorResource.cpp +++ b/service/resource-container/examples/DiscomfortIndexSensorBundle/src/DiscomfortIndexSensorResource.cpp @@ -66,8 +66,8 @@ void DiscomfortIndexSensorResource::executeLogic() void DiscomfortIndexSensorResource::onUpdatedInputResource(const std::string attributeName, std::vector values) { - double sum = 0; - double dConvert; + double sum = 0.0; + double dConvert = 0.0; int inputCount = 0; std::string itString; @@ -80,7 +80,11 @@ void DiscomfortIndexSensorResource::onUpdatedInputResource(const std::string att ++inputCount; } - double result = sum / inputCount; + double result = 0.0; + if (inputCount) + { + result = sum / inputCount; + } std::string indexCount;//string which will contain the indexCount std::stringstream convert; // stringstream used for the conversion convert << result;//add the value of Number to the characters in the stream diff --git a/service/resource-container/examples/DiscomfortIndexSensorBundle/src/inputSensors/THSensorApp/src/ThingResourceServer.cpp b/service/resource-container/examples/DiscomfortIndexSensorBundle/src/inputSensors/THSensorApp/src/ThingResourceServer.cpp index 0a11876..ed99f57 100644 --- a/service/resource-container/examples/DiscomfortIndexSensorBundle/src/inputSensors/THSensorApp/src/ThingResourceServer.cpp +++ b/service/resource-container/examples/DiscomfortIndexSensorBundle/src/inputSensors/THSensorApp/src/ThingResourceServer.cpp @@ -59,8 +59,8 @@ OCResourceHandle TemphumidResource::getHandle() void TemphumidResource::setResourceRepresentation(OCRepresentation &rep) { - int tempHumid; - int tempTemp; + int tempHumid = 0; + int tempTemp = 0; rep.getValue("humidity", tempTemp); rep.getValue("temperature", tempHumid); @@ -171,7 +171,7 @@ OCEntityHandlerResult entityHandler(std::shared_ptr< OCResourceRequest > request if (requestFlag & RequestHandlerFlag::ObserverFlag) { - pthread_t threadId; + pthread_t threadId = {}; cout << "\t\trequestFlag : Observer\n"; g_Observation = 1; @@ -212,7 +212,7 @@ int main() OC::OCPlatform::stopPresence(); } - catch (std::exception e) + catch (std::exception & e) { cout << e.what() << endl; } diff --git a/service/resource-container/examples/DiscomfortIndexSensorBundle/src/inputSensors/THSensorApp1/src/ThingResourceServer1.cpp b/service/resource-container/examples/DiscomfortIndexSensorBundle/src/inputSensors/THSensorApp1/src/ThingResourceServer1.cpp index fdcba11..a1c9f07 100644 --- a/service/resource-container/examples/DiscomfortIndexSensorBundle/src/inputSensors/THSensorApp1/src/ThingResourceServer1.cpp +++ b/service/resource-container/examples/DiscomfortIndexSensorBundle/src/inputSensors/THSensorApp1/src/ThingResourceServer1.cpp @@ -60,8 +60,8 @@ OCResourceHandle TemphumidResource::getHandle() void TemphumidResource::setResourceRepresentation(OCRepresentation &rep) { - int tempHumid; - int tempTemp; + int tempHumid = 0; + int tempTemp = 0; rep.getValue("humidity", tempTemp); rep.getValue("temperature", tempHumid); @@ -170,7 +170,7 @@ OCEntityHandlerResult entityHandler(std::shared_ptr< OCResourceRequest > request if (requestFlag & RequestHandlerFlag::ObserverFlag) { - pthread_t threadId; + pthread_t threadId = {}; cout << "\t\trequestFlag : Observer\n"; g_Observation = 1; @@ -211,7 +211,7 @@ int main() OC::OCPlatform::stopPresence(); } - catch (std::exception e) + catch (std::exception & e) { cout << e.what() << endl; } diff --git a/service/resource-container/examples/HueSampleBundle/src/HueConnector.cpp b/service/resource-container/examples/HueSampleBundle/src/HueConnector.cpp index de7121b..297faa1 100644 --- a/service/resource-container/examples/HueSampleBundle/src/HueConnector.cpp +++ b/service/resource-container/examples/HueSampleBundle/src/HueConnector.cpp @@ -68,8 +68,8 @@ void HueConnector::disconnect() std::string HueConnector::transmit(std::string target, std::string payload) { std::cout << "Transmitting to " << target << " " << payload << endl; - CURL *curl; - CURLcode res; + CURL *curl = NULL; + CURLcode res = CURLE_OK; struct curl_slist *headers = NULL; /* http headers to send with request */ /* set content type */ headers = curl_slist_append(headers, "Accept: application/json"); @@ -114,8 +114,8 @@ static int writer(char *data, size_t size, size_t nmemb, std::string *buffer_in) std::string HueConnector::read(std::string target) { std::cout << "Reading from to " << target << endl; - CURL *curl; - CURLcode res; + CURL *curl = NULL; + CURLcode res = CURLE_OK; struct curl_slist *headers = NULL; /* http headers to send with request */ /* set content type */ headers = curl_slist_append(headers, "Accept: application/json"); diff --git a/service/resource-container/src/Configuration.cpp b/service/resource-container/src/Configuration.cpp index fc5e1ae..3a7fd95 100644 --- a/service/resource-container/src/Configuration.cpp +++ b/service/resource-container/src/Configuration.cpp @@ -87,8 +87,8 @@ namespace OIC void Configuration::getConfiguredBundles(configInfo *configOutput) { - rapidxml::xml_node< char > *bundle; - rapidxml::xml_node< char > *subItem; + rapidxml::xml_node< char > *bundle = nullptr; + rapidxml::xml_node< char > *subItem = nullptr; string strKey, strValue; @@ -130,7 +130,7 @@ namespace OIC void Configuration::getBundleConfiguration(string bundleId, configInfo *configOutput) { - rapidxml::xml_node< char > *bundle; + rapidxml::xml_node< char > *bundle = nullptr; string strBundleId, strPath, strVersion; @@ -202,9 +202,11 @@ namespace OIC void Configuration::getResourceConfiguration(std::string bundleId, std::string resourceUri, resourceInfo *resourceInfoOut) { - rapidxml::xml_node< char > *bundle; - rapidxml::xml_node< char > *resource; - rapidxml::xml_node< char > *item, *subItem, *subItem2; + rapidxml::xml_node< char > *bundle = nullptr; + rapidxml::xml_node< char > *resource = nullptr; + rapidxml::xml_node< char > *item = nullptr; + rapidxml::xml_node< char > *subItem = nullptr; + rapidxml::xml_node< char > *subItem2 = nullptr; string strBundleId; string strKey, strValue; @@ -327,9 +329,11 @@ namespace OIC void Configuration::getResourceConfiguration(std::string bundleId, std::vector< resourceInfo > *configOutput) { - rapidxml::xml_node< char > *bundle; - rapidxml::xml_node< char > *resource; - rapidxml::xml_node< char > *item, *subItem, *subItem2; + rapidxml::xml_node< char > *bundle = nullptr; + rapidxml::xml_node< char > *resource = nullptr; + rapidxml::xml_node< char > *item = nullptr; + rapidxml::xml_node< char > *subItem = nullptr; + rapidxml::xml_node< char > *subItem2 = nullptr; string strBundleId; string strKey, strValue; @@ -347,7 +351,10 @@ namespace OIC bundle->next_sibling()) { // - strBundleId = bundle->first_node(BUNDLE_ID)->value(); + if (bundle->first_node(BUNDLE_ID)) + { + strBundleId = bundle->first_node(BUNDLE_ID)->value(); + } OIC_LOG_V(INFO, CONTAINER_TAG, "Comparing bundle ids %s - %s !", strBundleId.c_str(), bundleId.c_str()); diff --git a/service/resource-container/src/ResourceContainerImpl.cpp b/service/resource-container/src/ResourceContainerImpl.cpp index e22692d..099acd5 100644 --- a/service/resource-container/src/ResourceContainerImpl.cpp +++ b/service/resource-container/src/ResourceContainerImpl.cpp @@ -270,7 +270,7 @@ namespace OIC OIC_LOG_V(INFO, CONTAINER_TAG, "Unregister bundle: (%s)", std::string(m_bundles[id]->getID()).c_str()); - const char *error; + const char *error = NULL; dlclose(bundleHandle); if ((error = dlerror()) != NULL) @@ -690,7 +690,7 @@ namespace OIC void ResourceContainerImpl::registerSoBundle(shared_ptr bundleInfo) { OIC_LOG_V(DEBUG, CONTAINER_TAG, "Register SO bundle"); - const char *error; + const char *error = NULL; activator_t *bundleActivator = NULL; deactivator_t *bundleDeactivator = NULL; @@ -943,7 +943,7 @@ namespace OIC void ResourceContainerImpl::addSoBundleResource(const std::string &bundleId, resourceInfo newResourceInfo) { - resourceCreator_t *resourceCreator; + resourceCreator_t *resourceCreator = nullptr; resourceCreator = m_bundles[bundleId]->getResourceCreator(); diff --git a/service/resource-container/unittests/ResourceContainerTest.cpp b/service/resource-container/unittests/ResourceContainerTest.cpp index 94415c3..13436b5 100644 --- a/service/resource-container/unittests/ResourceContainerTest.cpp +++ b/service/resource-container/unittests/ResourceContainerTest.cpp @@ -57,7 +57,7 @@ string CONFIG_FILE = "ResourceContainerTestConfig.xml"; void getCurrentPath(std::string *pPath) { - char buffer[MAX_PATH]; + char buffer[MAX_PATH] = {0,}; #if defined(__linux__) char *strPath = NULL; diff --git a/service/resource-encapsulation/examples/linux/NestedAttributesClient.cpp b/service/resource-encapsulation/examples/linux/NestedAttributesClient.cpp index 4a7d87d..6ef9202 100644 --- a/service/resource-encapsulation/examples/linux/NestedAttributesClient.cpp +++ b/service/resource-encapsulation/examples/linux/NestedAttributesClient.cpp @@ -183,7 +183,7 @@ std::vector< std::vector< RCSResourceAttributes > > createNestedAttribute(int sp int processUserInput() { - int userInput; + int userInput = 0; std::cin >> userInput; if (std::cin.fail()) { @@ -201,7 +201,8 @@ void getAttributeFromRemoteServer() void setAttributeToRemoteServer() { - int speed, airc; + int speed = 0; + int airc = 0; std::cout << "\tEnter the Fan Speed you want to set : "; std::cin >> speed; diff --git a/service/resource-encapsulation/examples/linux/NestedAttributesServer.cpp b/service/resource-encapsulation/examples/linux/NestedAttributesServer.cpp index 66534f6..b85ea15 100644 --- a/service/resource-encapsulation/examples/linux/NestedAttributesServer.cpp +++ b/service/resource-encapsulation/examples/linux/NestedAttributesServer.cpp @@ -223,7 +223,7 @@ void initServer() int processUserInput() { - int userInput; + int userInput = 0; std::cin >> userInput; if (std::cin.fail()) { diff --git a/service/resource-encapsulation/examples/linux/SampleResourceClient.cpp b/service/resource-encapsulation/examples/linux/SampleResourceClient.cpp index cf0ff40..0a894c1 100644 --- a/service/resource-encapsulation/examples/linux/SampleResourceClient.cpp +++ b/service/resource-encapsulation/examples/linux/SampleResourceClient.cpp @@ -87,7 +87,7 @@ int processUserInput(int min = std::numeric_limits::min(), { assert(min <= max); - int input; + int input = 0; std::cin >> input; std::cin.ignore(std::numeric_limits::max(), '\n'); @@ -423,16 +423,16 @@ std::string selectResourceType() switch (processUserInput(RESOURCE_TEMP, RESOURCE_LIGHT)) { - case RESOURCE_TEMP: - { - g_attrKey = "Temperature"; - return RESOURCE_TYPE_TEMP; - } - case RESOURCE_LIGHT: - { - g_attrKey = "Brightness"; - return RESOURCE_TYPE_LIGHT; - } + case RESOURCE_TEMP: + { + g_attrKey = "Temperature"; + return RESOURCE_TYPE_TEMP; + } + case RESOURCE_LIGHT: + { + g_attrKey = "Brightness"; + return RESOURCE_TYPE_LIGHT; + } } throw std::logic_error("unreachable"); diff --git a/service/resource-encapsulation/examples/linux/SampleResourceServer.cpp b/service/resource-encapsulation/examples/linux/SampleResourceServer.cpp index 65b9cd6..4ac4038 100644 --- a/service/resource-encapsulation/examples/linux/SampleResourceServer.cpp +++ b/service/resource-encapsulation/examples/linux/SampleResourceServer.cpp @@ -53,7 +53,7 @@ int processUserInput(int min, int max) { assert(min <= max); - int input; + int input = 0; std::cin >> input; @@ -178,7 +178,7 @@ void runResourceTypeSelection(int resourceMode) std::cout << "========================================================\n"; int resourceType = processUserInput(RESOURCE_TEMP, RESOURCE_LIGHT); - DisplayControlMenuFunc displayMenuFunc; + DisplayControlMenuFunc displayMenuFunc = nullptr; std::string attrKey; switch (resourceType) diff --git a/service/resource-encapsulation/examples/linux/SeparateResponseServer.cpp b/service/resource-encapsulation/examples/linux/SeparateResponseServer.cpp index 4c9b4f6..1a76655 100755 --- a/service/resource-encapsulation/examples/linux/SeparateResponseServer.cpp +++ b/service/resource-encapsulation/examples/linux/SeparateResponseServer.cpp @@ -70,7 +70,7 @@ int processUserInput(int min, int max) { assert(min <= max); - int input; + int input = 0; while(true) { diff --git a/service/resource-encapsulation/src/common/expiryTimer/unittests/ExpiryTimerTest.cpp b/service/resource-encapsulation/src/common/expiryTimer/unittests/ExpiryTimerTest.cpp index c91597b..258a28a 100644 --- a/service/resource-encapsulation/src/common/expiryTimer/unittests/ExpiryTimerTest.cpp +++ b/service/resource-encapsulation/src/common/expiryTimer/unittests/ExpiryTimerTest.cpp @@ -97,7 +97,7 @@ TEST_F(ExpiryTimerImplTest, CallbackBeInvokedWithinTolerance) TEST_F(ExpiryTimerImplTest, CallbackBeInvokedWithTimerId) { - ExpiryTimerImpl::Id returnedId; + ExpiryTimerImpl::Id returnedId = 0; FunctionObject* functor = mocks.Mock< FunctionObject >(); mocks.ExpectCall(functor, FunctionObject::execute).Match( @@ -236,7 +236,7 @@ TEST_F(ExpiryTimerTest, CallbackBeInvokedWithinTolerance) TEST_F(ExpiryTimerTest, CallbackBeInvokedWithTimerId) { - ExpiryTimer::Id returnedId; + ExpiryTimer::Id returnedId = 0; FunctionObject* functor = mocks.Mock< FunctionObject >(); mocks.ExpectCall(functor, FunctionObject::execute).Match( diff --git a/service/resource-encapsulation/src/resourceBroker/unittest/ResourceBrokerUnitTest.cpp b/service/resource-encapsulation/src/resourceBroker/unittest/ResourceBrokerUnitTest.cpp index 478f716..69f1612 100644 --- a/service/resource-encapsulation/src/resourceBroker/unittest/ResourceBrokerUnitTest.cpp +++ b/service/resource-encapsulation/src/resourceBroker/unittest/ResourceBrokerUnitTest.cpp @@ -108,7 +108,7 @@ TEST_F(ResourceBrokerTest,CancelHostResource_NoThrowIfNormalParams) MockingFunc(); - BrokerID ret; + BrokerID ret = 0; ret = brokerInstance->hostResource(pResource,cb); ASSERT_NO_THROW(brokerInstance->cancelHostResource(ret)); @@ -137,7 +137,7 @@ TEST_F(ResourceBrokerTest,getResourceState_ReturnNormalValueIfNormalId) MockingFunc(); - BrokerID ret; + BrokerID ret = 0; ret = brokerInstance->hostResource(pResource,cb); ASSERT_NE(brokerInstance->getResourceState(ret),BROKER_STATE::NONE); @@ -160,7 +160,7 @@ TEST_F(ResourceBrokerTest,getResourceState_ReturnNormalValueIfNormalResource) MockingFunc(); - BrokerID ret; + BrokerID ret = 0; ret = brokerInstance->hostResource(pResource,cb); ASSERT_NE(brokerInstance->getResourceState(pResource),BROKER_STATE::NONE); @@ -181,8 +181,8 @@ TEST_F(ResourceBrokerTest,getResourceState_NormalErrorHandlingIfAbnormalResource MockingFunc(); - PrimitiveResource::Ptr resource[3]; - BrokerID id[3]; + PrimitiveResource::Ptr resource[3] = {nullptr,}; + BrokerID id[3] = {0,}; for(int i=0;i!=3;i++) { diff --git a/service/resource-encapsulation/src/resourceBroker/unittest/ResourcePresenceUnitTest.cpp b/service/resource-encapsulation/src/resourceBroker/unittest/ResourcePresenceUnitTest.cpp index d87d186..0199887 100644 --- a/service/resource-encapsulation/src/resourceBroker/unittest/ResourcePresenceUnitTest.cpp +++ b/service/resource-encapsulation/src/resourceBroker/unittest/ResourcePresenceUnitTest.cpp @@ -97,7 +97,7 @@ TEST_F(ResourcePresenceTest,timeoutCB_TimeOverWhenIsRequestGet) MockingFunc(); instance->initializeResourcePresence(pResource); std::cout<<"wait while done timeout requestGet\n"; - BROKER_STATE state; + BROKER_STATE state = BROKER_STATE::NONE; state = instance->getResourceState(); sleep((BROKER_DEVICE_PRESENCE_TIMEROUT/1000)+1); ASSERT_EQ(state,instance->getResourceState()); -- 2.7.4