[IOT-2746][ES] Static analysis warning fix. 19/22819/2
authorHarry <h.marappa@samsung.com>
Fri, 13 Oct 2017 10:54:11 +0000 (16:24 +0530)
committerAshok Babu Channa <ashok.channa@samsung.com>
Sun, 15 Oct 2017 19:10:45 +0000 (19:10 +0000)
Fixed all the static analyzer reported issues in
ES native code.

Change-Id: Ida916ed651fcdf4f02f3549ce987511ca8d5eaa0
Signed-off-by: Harry <h.marappa@samsung.com>
service/easy-setup/enrollee/inc/internal/es_util.h
service/easy-setup/enrollee/src/es_util.c
service/easy-setup/enrollee/unittests/ESEnrolleeTest.cpp
service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/jni/JniEsUtils.h
service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/jni/JniRemoteEnrollee.cpp
service/easy-setup/mediator/richsdk/src/RemoteEnrollee.cpp
service/easy-setup/sampleapp/enrollee/arduino/enrolleewifi.cpp
service/easy-setup/sampleapp/enrollee/linux/enrolleewifi.c
service/easy-setup/sampleapp/enrollee/tizen-sdb/EnrolleeSample/easysetup_wifi_conn.c
service/easy-setup/sampleapp/enrollee/tizen-sdb/EnrolleeSample/enrolleewifi.cpp

index b057841..cfb7922 100644 (file)
@@ -36,9 +36,7 @@ extern "C"
 // false is returned by the function.
 
 const char* WiFiModeEnumToString(WIFI_MODE val);
-bool WiFiModeStringToEnum(const char *valIn, WIFI_MODE *valOut);
 const char* WiFiFreqEnumToString(WIFI_FREQ val);
-bool WiFiFreqStringToEnum(const char *val, WIFI_FREQ *valOut);
 const char* WiFiAuthTypeEnumToString(WIFI_AUTHTYPE val);
 bool WiFiAuthTypeStringToEnum(const char *val, WIFI_AUTHTYPE *valOut);
 const char* WiFiEncTypeEnumToString(WIFI_ENCTYPE val);
index 498197c..621cfd4 100644 (file)
@@ -116,13 +116,6 @@ const char* WiFiModeEnumToString(WIFI_MODE val)
     return ret;
 }
 
-bool WiFiModeStringToEnum(const char *valIn, WIFI_MODE *valOut)
-{
-    bool result = false;
-    LookupStrToEnum(valIn, wifiModeConvertLookup, (*valOut), result);
-    return result;
-}
-
 const char* WiFiFreqEnumToString(WIFI_FREQ val)
 {
     char *ret = NULL;
@@ -130,13 +123,6 @@ const char* WiFiFreqEnumToString(WIFI_FREQ val)
     return ret;
 }
 
-bool WiFiFreqStringToEnum(const char *val, WIFI_FREQ *valOut)
-{
-    bool result = false;
-    LookupStrToEnum(val, wifiFreqConvertLookup, (*valOut), result);
-    return result;
-}
-
 const char* WiFiAuthTypeEnumToString(WIFI_AUTHTYPE val)
 {
     char *ret = NULL;
index fcd76c8..a2e55e8 100644 (file)
@@ -294,6 +294,8 @@ TEST_F(EasysetupEnrolleeTest, FindProvisioningResourceAtEnrolleeWithSuccess)
 TEST_F(EasysetupEnrolleeTest, SetDevicePropertyWithSuccess)
 {
     ESResult ret = startEnrollee();
+    ASSERT_EQ(ES_OK, ret);
+
     ret = setDeviceProperty();
     EXPECT_EQ(ret, ES_OK);
     ESTerminateEnrollee();
@@ -302,6 +304,8 @@ TEST_F(EasysetupEnrolleeTest, SetDevicePropertyWithSuccess)
 TEST_F(EasysetupEnrolleeTest, SetProvStatusWithSuccess)
 {
     ESResult ret = startEnrollee();
+    ASSERT_EQ(ES_OK, ret);
+
     ret = ESSetState(ES_STATE_CONNECTED_TO_ENROLLER);
     EXPECT_EQ(ret, ES_OK);
     ESTerminateEnrollee();
@@ -310,6 +314,8 @@ TEST_F(EasysetupEnrolleeTest, SetProvStatusWithSuccess)
 TEST_F(EasysetupEnrolleeTest, SetErrorCodeWithSuccess)
 {
     ESResult ret = startEnrollee();
+    ASSERT_EQ(ES_OK, ret);
+
     ret = ESSetErrorCode(ES_ERRCODE_PW_WRONG);
     EXPECT_EQ(ret, ES_OK);
     ESTerminateEnrollee();
@@ -333,7 +339,10 @@ TEST_F(EasysetupEnrolleeTest, DevicePropertyIsWellConstructedInResponsePayload)
         });
 
     ESResult ret = startEnrollee();
+    ASSERT_EQ(ES_OK, ret);
+
     ret = setDeviceProperty();
+    EXPECT_EQ(ES_OK, ret);
 
     g_mediatorSimul.getConfiguration(onGetConfiguration);
 
@@ -365,9 +374,16 @@ TEST_F(EasysetupEnrolleeTest, ProvisioningPropertiesIsWellConstructedInResponseP
         });
 
     ESResult ret = startEnrollee();
+    ASSERT_EQ(ES_OK, ret);
+
     ret = setDeviceProperty();
+    EXPECT_EQ(ES_OK, ret);
+
     ret = ESSetState(ES_STATE_CONNECTED_TO_ENROLLER);
+    EXPECT_EQ(ES_OK, ret);
+
     ret = ESSetErrorCode(ES_ERRCODE_NO_INTERNETCONNECTION);
+    EXPECT_EQ(ES_OK, ret);
 
     g_mediatorSimul.getStatus(onGetStatus);
 
@@ -402,7 +418,9 @@ TEST_F(EasysetupEnrolleeTest, WiFiAndDevConfProperiesProvisionedWithSuccess)
             }
         });
 
-    startEnrollee();
+
+    ESResult ret = startEnrollee();
+    ASSERT_EQ(ES_OK, ret);
 
     g_mediatorSimul.provisionDeviceProperties(deviceProvisioningStatusCallback);
 
@@ -438,7 +456,8 @@ TEST_F(EasysetupEnrolleeTest, CloudServerProperiesProvisionedWithSuccess)
             }
         });
 
-    startEnrollee();
+    ESResult ret = startEnrollee();
+    ASSERT_EQ(ES_OK, ret);
 
     g_mediatorSimul.provisionCloudProperties(cloudProvisioningStatusCallback);
 
@@ -460,6 +479,8 @@ TEST_F(EasysetupEnrolleeTest, GetWifiRsrcTest)
         });
 
     ESResult ret = startEnrollee();
+    ASSERT_EQ(ES_OK, ret);
+
     g_mediatorSimul.getWifiRsrc(onGetWifiRsrc);
 
     std::unique_lock< std::mutex > lock{ mutexForCondition };
@@ -480,6 +501,8 @@ TEST_F(EasysetupEnrolleeTest, GetCloudRsrcTest)
         });
 
     ESResult ret = startEnrollee();
+    ASSERT_EQ(ES_OK, ret);
+
     g_mediatorSimul.getCloudRsrc(onGetCloudRsrc);
 
     std::unique_lock< std::mutex > lock{ mutexForCondition };
@@ -500,7 +523,10 @@ TEST_F(EasysetupEnrolleeTest, GetDevConfTest)
         });
 
     ESResult ret = startEnrollee();
+    ASSERT_EQ(ES_OK, ret);
+
     ret = setDeviceProperty();
+    EXPECT_EQ(ES_OK, ret);
 
     g_mediatorSimul.getDevConfiguration(onGetDeviceConf);
 
@@ -522,6 +548,7 @@ TEST_F(EasysetupEnrolleeTest, PutRequestTest)
         });
 
     ESResult ret = startEnrollee();
+    ASSERT_EQ(ES_OK, ret);
 
     g_mediatorSimul.putProvRsrc(onPutRequest);
 
index 2ff5076..94a4e79 100644 (file)
@@ -42,13 +42,4 @@ using namespace OIC::Service;
  */
 void throwESException(JNIEnv *env, std::string reason);
 
-/**
-* @brief Convert integer to OCconnectivity Enum
-*/
-OCConnectivityType  getOCConnectivityTypeFromInt(int connectivityType);
-
-WIFI_AUTHTYPE getWifiAuthTypeFromInt(int authType);
-WIFI_ENCTYPE getWifiEncTypeFromInt(int encType);
-int convertNativeWifiFreqToInt(WIFI_FREQ wifiFreq);
-int convertNativeWifiModeToInt(WIFI_MODE wifiMode);
 #endif //__JNI_ES_UTILS_H_
index 06bbc42..37f297d 100644 (file)
@@ -68,7 +68,7 @@ void JniRemoteEnrollee::getStatus(JNIEnv *env, jobject jListener)
     {
         m_sharedResource->getStatus(getEnrolleeStatusCallback);
     }
-    catch (ESBadRequestException &exception)
+    catch (const ESBadRequestException &exception)
     {
         ES_LOGE("JNI getStatus :: Exception occured");
         //throw the exception to java
@@ -91,7 +91,7 @@ void JniRemoteEnrollee::getConfiguration(JNIEnv *env, jobject jListener)
     {
         m_sharedResource->getConfiguration(getConfigurationStatusCallback);
     }
-    catch (ESBadRequestException &exception)
+    catch (const ESBadRequestException &exception)
     {
         ES_LOGE("JNI getConfiguration :: Exception occured");
         //throw the exception to java
@@ -114,7 +114,7 @@ void JniRemoteEnrollee::provisionSecurity(JNIEnv *env, jobject jListener)
     {
         m_sharedResource->provisionSecurity(secProvStatusCallback);
     }
-    catch (ESBadRequestException &exception)
+    catch (const ESBadRequestException &exception)
     {
         ES_LOGE("JNI provisionSecurity :: Exception occured");
         //throw the exception to java
@@ -146,7 +146,7 @@ void JniRemoteEnrollee::provisionDeviceProperties(JNIEnv *env,
     {
         m_sharedResource->provisionDeviceProperties(deviceProp, devicePropProvStatusCallback);
     }
-    catch (ESBadRequestException &exception)
+    catch (const ESBadRequestException &exception)
     {
         ES_LOGE("JNI provisionDeviceProperties :: Exception occured");
         //throw the exception to java
@@ -188,7 +188,7 @@ void JniRemoteEnrollee::provisionCloudProperties(JNIEnv *env,
     {
         m_sharedResource->provisionCloudProperties(cloudProp, cloudPropProvStatusCallback);
     }
-    catch (ESBadRequestException &exception)
+    catch (const ESBadRequestException &exception)
     {
         ES_LOGE("JNI startProvisioning :: Exception occured");
         //throw the exception to java
index dd59616..3217037 100644 (file)
@@ -504,10 +504,7 @@ namespace OIC
         {
             OIC_LOG(INFO, ES_REMOTE_ENROLLEE_TAG, "initCloudResource IN");
 
-            ESResult result = ES_ERROR;
-
-            result = discoverResource();
-
+            ESResult result = discoverResource();
             if (result == ES_ERROR)
             {
                 OIC_LOG(ERROR, ES_REMOTE_ENROLLEE_TAG,
index d867f51..6f3b679 100644 (file)
@@ -127,7 +127,7 @@ void EventCallbackInApp(ESResult esResult, ESEnrolleeState enrolleeState)
             Serial.println("Device is successfully OnBoarded");
             g_OnBoardingSucceeded = true;
         }
-        else if(g_OnBoardingSucceeded & enrolleeState == ES_ON_BOARDED_STATE){
+        else if(g_OnBoardingSucceeded && enrolleeState == ES_ON_BOARDED_STATE){
             Serial.println("Device is successfully OnBoared with SoftAP");
             g_ProvisioningSucceeded = true;
         }
@@ -242,12 +242,13 @@ void setup()
 // The loop function is called in an endless loop
 void loop()
 {
-    char buffer[5] = {0};
-    size_t len;
     if (Serial.available() > 0)
     {
+        char buffer[5] = {0};
+        size_t len = 0;
+
         GetData(buffer, sizeof(buffer), &len);
-        if (0 >= len)
+        if (0 == len)
         {
             Serial.println("Input Error err");
             return;
index 93522dd..20fc972 100644 (file)
@@ -215,7 +215,7 @@ void SetDeviceInfo()
     char userValue_str[] = "user_str";
     g_userProperties.userValue_int = 0;
 
-    strncpy(g_userProperties.userValue_str, userValue_str, strlen(userValue_str) + 1);
+    strncpy(g_userProperties.userValue_str, userValue_str, MAXLEN_STRING);
     SetUserProperties(&g_userProperties);
 
     if(ESSetDeviceProperty(&deviceProperty) == ES_ERROR)
index d8ff9fd..876e05e 100644 (file)
@@ -253,12 +253,12 @@ WiFiConnErrCode TizenWiFiConn(char *ssid, char* passwd)
     memset(targetInfo.wifiPasswd, 0, OIC_STRING_MAX_VALUE);
     if(ssid != NULL)
     {
-        strncpy(targetInfo.wifiName, ssid, strlen(ssid));
+        strncpy(targetInfo.wifiName, ssid, OIC_STRING_MAX_VALUE);
     }
 
     if(passwd != NULL)
     {
-        strncpy(targetInfo.wifiPasswd, passwd, strlen(passwd));
+        strncpy(targetInfo.wifiPasswd, passwd, OIC_STRING_MAX_VALUE);
     }
 
     int ret = wifi_foreach_found_aps(WiFiFoundCallback, &targetInfo);
index b04f5a0..5f1ec2d 100644 (file)
@@ -115,12 +115,12 @@ void WiFiConfProvCbInApp(ESWiFiConfData *eventData)
     memset(gPasswd, 0, OIC_STRING_MAX_VALUE);
     if(eventData->ssid != NULL)
     {
-        strncpy(gSSID, eventData->ssid, strlen(eventData->ssid));
+        strncpy(gSSID, eventData->ssid, OIC_STRING_MAX_VALUE);
     }
 
     if(eventData->pwd != NULL)
     {
-        strncpy(gPasswd, eventData->pwd, strlen(eventData->pwd));
+        strncpy(gPasswd, eventData->pwd, OIC_STRING_MAX_VALUE);
     }
 
     cout << "WiFiConfProvCbInApp OUT" << endl;