Fix a defect detected by static code analyzer
authorJaewook Jung <jw0213.jung@samsung.com>
Fri, 14 Apr 2017 02:34:00 +0000 (11:34 +0900)
committerAshok Babu Channa <ashok.channa@samsung.com>
Mon, 17 Apr 2017 04:43:17 +0000 (04:43 +0000)
Because the size of the struct CAEndpoint_t is 184 bytes,
it is better to pass a pointer of it if call-by-value is not
necessary.

Change-Id: I680cb11ba6ad18613370a76333002d7784a23178
Signed-off-by: Jaewook Jung <jw0213.jung@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/18955
Tested-by: jenkins-iotivity <jenkins@iotivity.org>
Reviewed-by: jaehyun Cho <jaehyun3.cho@samsung.com>
Reviewed-by: Ashok Babu Channa <ashok.channa@samsung.com>
resource/csdk/connectivity/api/cautilinterface.h
resource/csdk/connectivity/util/inc/caconnectionmanager.h
resource/csdk/connectivity/util/src/camanager/caconnectionmanager.c
resource/csdk/connectivity/util/src/camanager/camanagerutil.c
resource/csdk/connectivity/util/src/camanager/camanagerutil.h
resource/csdk/connectivity/util/src/camanager/camessagearbiter.c
resource/csdk/connectivity/util/src/camanager/camessagearbiter.h
resource/csdk/connectivity/util/src/cautilinterface.c
resource/csdk/stack/src/occonnectionmanager.c

index 5c460eb..e98c02f 100644 (file)
@@ -152,7 +152,7 @@ CAResult_t CAUtilCMTerminate();
  * @param[in]  isCloud    with cloud or not.
  * @return ::CA_STATUS_OK or Appropriate error code.
  */
-CAResult_t CAUtilCMUpdateRemoteDeviceInfo(const CAEndpoint_t endpoint, bool isCloud);
+CAResult_t CAUtilCMUpdateRemoteDeviceInfo(const CAEndpoint_t *endpoint, bool isCloud);
 
 /**
  * Reset RemoteDevice Info. for Connection Manager
index 16ef031..f5c15a3 100644 (file)
@@ -82,7 +82,7 @@ CAResult_t CACMGetConnUserConfig(CAConnectUserPref_t *connPrefer);
  * @param[in]  isCloud        with cloud or not .
  * @return ::CA_STATUS_OK or Appropriate error code.
  */
-CAResult_t CACMUpdateRemoteDeviceInfo(const CAEndpoint_t endpoint, bool isCloud);
+CAResult_t CACMUpdateRemoteDeviceInfo(const CAEndpoint_t *endpoint, bool isCloud);
 
 /**
  * Reset Remote Device Info.
index 12e54f3..1a9e5b4 100644 (file)
@@ -75,7 +75,7 @@ CAResult_t CACMGetMessageData(CAData_t *data)
     return CAMsgArbiterGetMessageData(data);
 }
 
-CAResult_t CACMUpdateRemoteDeviceInfo(const CAEndpoint_t endpoint, bool isCloud)
+CAResult_t CACMUpdateRemoteDeviceInfo(const CAEndpoint_t *endpoint, bool isCloud)
 {
     return CAMsgArbiterUpdateDeviceInfo(endpoint, isCloud);
 }
index b6844fd..f12c715 100644 (file)
@@ -23,6 +23,7 @@
 #include <stdio.h>
 #include <string.h>
 #include <ctype.h>
+#include <assert.h>
 
 #include "caadapterutils.h"
 #include "logger.h"
@@ -57,24 +58,25 @@ static void CAMgrUtilDevInfoListPrint(CMDeviceInfoList_t *devInfoList);
  *
  * @return :: new alloced CMDeviceInfo_t pointer structure or NULL.
  */
-static CMDeviceInfo_t* CAMgrUtilDevInfoCreate(const CAEndpoint_t endpoint);
+static CMDeviceInfo_t* CAMgrUtilDevInfoCreate(const CAEndpoint_t *endpoint);
 
 
 CAResult_t CAMgrUtilAddDevInfoToList(CMDeviceInfoList_t **devInfoList,
-                                     const CAEndpoint_t endpoint)
+                                     const CAEndpoint_t *endpoint)
 {
     OIC_LOG(DEBUG, TAG, "IN");
 
     VERIFY_NON_NULL(devInfoList, TAG, "devInfoList");
-    VERIFY_NON_NULL(endpoint.remoteId, TAG, "deviceId");
-    VERIFY_NON_NULL(endpoint.addr, TAG, "address");
+    VERIFY_NON_NULL(endpoint, TAG, "endpoint");
+    VERIFY_NON_NULL(endpoint->remoteId, TAG, "deviceId");
+    VERIFY_NON_NULL(endpoint->addr, TAG, "address");
 
     CMDeviceInfo_t *node = NULL;
-    CAResult_t ret = CAMgrUtilGetDevInfo(*devInfoList, endpoint.remoteId, &node);
+    CAResult_t ret = CAMgrUtilGetDevInfo(*devInfoList, endpoint->remoteId, &node);
 
     if (CA_STATUS_OK == ret)
     {
-        OIC_LOG_V(ERROR, TAG, "deviceId[%s] is already added into list", endpoint.remoteId);
+        OIC_LOG_V(ERROR, TAG, "deviceId[%s] is already added into list", endpoint->remoteId);
         return CA_STATUS_FAILED;
     }
 
@@ -132,39 +134,40 @@ CAResult_t CAMgrUtilGetDevInfo(CMDeviceInfoList_t *devInfoList, const char *devi
     return CA_STATUS_FAILED;
 }
 
-CAResult_t CAMgrUtilUpdateDevInfo(CMDeviceInfoList_t *devInfoList, const CAEndpoint_t endpoint)
+CAResult_t CAMgrUtilUpdateDevInfo(CMDeviceInfoList_t *devInfoList, const CAEndpoint_t *endpoint)
 {
     OIC_LOG(DEBUG, TAG, "IN");
 
     VERIFY_NON_NULL(devInfoList, TAG, "devInfoList");
-    VERIFY_NON_NULL(endpoint.remoteId, TAG, "deviceId");
-    VERIFY_NON_NULL(endpoint.addr, TAG, "localAddr");
+    VERIFY_NON_NULL(endpoint, TAG, "endpoint");
+    VERIFY_NON_NULL(endpoint->remoteId, TAG, "deviceId");
+    VERIFY_NON_NULL(endpoint->addr, TAG, "localAddr");
 
     CMDeviceInfo_t *node = NULL;
-    CAResult_t ret = CAMgrUtilGetDevInfo(devInfoList, endpoint.remoteId, &node);
+    CAResult_t ret = CAMgrUtilGetDevInfo(devInfoList, endpoint->remoteId, &node);
 
     if (CA_STATUS_OK != ret || NULL == node)
     {
-        OIC_LOG_V(ERROR, TAG, "deviceId[%s] isn't included in list", endpoint.remoteId);
+        OIC_LOG_V(ERROR, TAG, "deviceId[%s] isn't included in list", endpoint->remoteId);
         return ret;
     }
 
-    node->d2dInfo.adapter |= endpoint.adapter;
-    node->d2dInfo.flags |= endpoint.flags;
+    node->d2dInfo.adapter |= endpoint->adapter;
+    node->d2dInfo.flags |= endpoint->flags;
 
     if (NULL != node->d2dInfo.addr)
     {
         OICFree(node->d2dInfo.addr);
     }
-    node->d2dInfo.addr = OICStrdup(endpoint.addr);
+    node->d2dInfo.addr = OICStrdup(endpoint->addr);
 
-    if (CA_ADAPTER_IP & endpoint.adapter)
+    if (CA_ADAPTER_IP & endpoint->adapter)
     {
-        node->d2dInfo.udpPort = endpoint.port;
+        node->d2dInfo.udpPort = endpoint->port;
     }
-    else if (CA_ADAPTER_TCP & endpoint.adapter)
+    else if (CA_ADAPTER_TCP & endpoint->adapter)
     {
-        node->d2dInfo.tcpPort = endpoint.port;
+        node->d2dInfo.tcpPort = endpoint->port;
     }
 
     CAMgrUtilDevInfoListPrint(devInfoList);
@@ -221,12 +224,13 @@ void CAMgrUtilDestroyDevInfoList(CMDeviceInfoList_t *devInfoList)
     OIC_LOG(DEBUG, TAG, "OUT");
 }
 
-static CMDeviceInfo_t* CAMgrUtilDevInfoCreate(const CAEndpoint_t endpoint)
+static CMDeviceInfo_t* CAMgrUtilDevInfoCreate(const CAEndpoint_t *endpoint)
 {
     OIC_LOG(DEBUG, TAG, "IN");
 
-    VERIFY_NON_NULL_RET(endpoint.remoteId, TAG, "remoteId", NULL);
-    VERIFY_NON_NULL_RET(endpoint.addr, TAG, "cloudAddr", NULL);
+    assert(endpoint);
+    assert(endpoint->remoteId);
+    assert(endpoint->addr);
 
     CMDeviceInfo_t *node = (CMDeviceInfo_t *)OICCalloc(1, sizeof(CMDeviceInfo_t));
     if (NULL == node)
@@ -235,13 +239,13 @@ static CMDeviceInfo_t* CAMgrUtilDevInfoCreate(const CAEndpoint_t endpoint)
         return NULL;
     }
 
-    node->deviceId = OICStrdup(endpoint.remoteId);
+    node->deviceId = OICStrdup(endpoint->remoteId);
 
-    node->d2sInfo.adapter = endpoint.adapter;
-    node->d2sInfo.flags = endpoint.flags;
-    node->d2sInfo.addr = OICStrdup(endpoint.addr);
+    node->d2sInfo.adapter = endpoint->adapter;
+    node->d2sInfo.flags = endpoint->flags;
+    node->d2sInfo.addr = OICStrdup(endpoint->addr);
     node->d2sInfo.udpPort = 0;
-    node->d2sInfo.tcpPort = endpoint.port;
+    node->d2sInfo.tcpPort = endpoint->port;
 
     node->d2dInfo.adapter = 0;
     node->d2dInfo.flags = 0;
index 6aff40f..adf41cd 100644 (file)
@@ -76,7 +76,7 @@ typedef struct CMDeviceInfoList
  * @retval :: CA_STATUS_FAILED Operation failed.
  */
 CAResult_t CAMgrUtilAddDevInfoToList(CMDeviceInfoList_t **devInfoList,
-                                     const CAEndpoint_t endpoint);
+                                     const CAEndpoint_t *endpoint);
 
 /**
  * This function is used to get the DeviceInfo which have specific device id
@@ -107,7 +107,7 @@ CAResult_t CAMgrUtilGetDevInfo(CMDeviceInfoList_t *devInfoList, const char *devi
  * @retval :: CA_STATUS_FAILED Operation failed.
  */
 CAResult_t CAMgrUtilUpdateDevInfo(CMDeviceInfoList_t *devInfoList,
-                                  const CAEndpoint_t endpoint);
+                                  const CAEndpoint_t *endpoint);
 
 /**
  * This function is used to reset all D2D informations.
index 741ceff..ff5f536 100644 (file)
@@ -207,14 +207,14 @@ CAResult_t CAMsgArbiterGetMessageData(CAData_t *data)
     return ret;
 }
 
-CAResult_t CAMsgArbiterUpdateDeviceInfo(const CAEndpoint_t endpoint, bool isCloud)
+CAResult_t CAMsgArbiterUpdateDeviceInfo(const CAEndpoint_t *endpoint, bool isCloud)
 {
     OIC_LOG(DEBUG, TAG, "IN - CAMsgArbiterUpdateDeviceInfo");
 
-    VERIFY_NON_NULL(endpoint.remoteId, TAG, "remoteId");
+    VERIFY_NON_NULL(endpoint, TAG, "endpoint");
+    VERIFY_NON_NULL(endpoint->remoteId, TAG, "remoteId");
 
     CAResult_t ret = CA_STATUS_FAILED;
-    const char *deviceId = endpoint.remoteId;
 
     if (isCloud)
     {
@@ -228,7 +228,8 @@ CAResult_t CAMsgArbiterUpdateDeviceInfo(const CAEndpoint_t endpoint, bool isClou
             return ret;
         }
 
-        OIC_LOG_V(DEBUG, TAG, "device id[%s] is successfully added into list!", deviceId);
+        OIC_LOG_V(DEBUG, TAG, "device id[%s] is successfully added into list!",
+                  endpoint->remoteId);
     }
     else
     {
@@ -238,11 +239,12 @@ CAResult_t CAMsgArbiterUpdateDeviceInfo(const CAEndpoint_t endpoint, bool isClou
 
         if (CA_STATUS_OK != ret)
         {
-            OIC_LOG_V(ERROR, TAG, "device id[%s] is not included in list", deviceId);
+            OIC_LOG_V(ERROR, TAG, "device id[%s] is not included in list", endpoint->remoteId);
             return ret;
         }
 
-        OIC_LOG_V(DEBUG, TAG, "device id[%s] is successfully updated into list!", deviceId);
+        OIC_LOG_V(DEBUG, TAG, "device id[%s] is successfully updated into list!",
+                  endpoint->remoteId);
     }
 
     OIC_LOG(DEBUG, TAG, "OUT - CAMsgArbiterUpdateDeviceInfo");
index 44ea9b0..c27f308 100644 (file)
@@ -51,7 +51,7 @@ CAResult_t CAMsgArbiterTerminate();
  * @param[in]  isCloud        with cloud or not .
  * @return ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
  */
-CAResult_t CAMsgArbiterUpdateDeviceInfo(const CAEndpoint_t endpoint, bool isCloud);
+CAResult_t CAMsgArbiterUpdateDeviceInfo(const CAEndpoint_t *endpoint, bool isCloud);
 
 /**
  * Reset Device Info in managed data
index 1debea1..8508ba3 100644 (file)
@@ -180,7 +180,7 @@ CAResult_t CAUtilCMTerminate()
     return CACMTerminate();
 }
 
-CAResult_t CAUtilCMUpdateRemoteDeviceInfo(const CAEndpoint_t endpoint, bool isCloud)
+CAResult_t CAUtilCMUpdateRemoteDeviceInfo(const CAEndpoint_t *endpoint, bool isCloud)
 {
     return CACMUpdateRemoteDeviceInfo(endpoint, isCloud);
 }
index c60740d..269378d 100755 (executable)
@@ -183,7 +183,7 @@ OCStackResult OCCMDiscoveryResource(OCClientResponse *clientResponse)
     CAEndpoint_t endpoint = {.adapter = CA_DEFAULT_ADAPTER};
     CopyDevAddrToEndpoint(&(clientResponse->devAddr), &endpoint);
 
-    CAResult_t ret = CAUtilCMUpdateRemoteDeviceInfo(endpoint, isCloud);
+    CAResult_t ret = CAUtilCMUpdateRemoteDeviceInfo(&endpoint, isCloud);
     if (CA_STATUS_OK != ret)
     {
         OIC_LOG(ERROR, TAG, "CAUtilCMUpdateRemoteDeviceInfo is failed.");
@@ -196,7 +196,7 @@ OCStackResult OCCMDiscoveryResource(OCClientResponse *clientResponse)
         endpoint.adapter = CA_ADAPTER_TCP;
         endpoint.port = resource->tcpPort;
 
-        ret = CAUtilCMUpdateRemoteDeviceInfo(endpoint, isCloud);
+        ret = CAUtilCMUpdateRemoteDeviceInfo(&endpoint, isCloud);
         if (CA_STATUS_OK != ret)
         {
             OIC_LOG(ERROR, TAG, "CAUtilCMUpdateRemoteDeviceInfo is failed!");