From 4b3054591ed075e5647561669415494391570ba3 Mon Sep 17 00:00:00 2001 From: Jaewook Jung Date: Fri, 14 Apr 2017 11:34:00 +0900 Subject: [PATCH] Fix a defect detected by static code analyzer 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 Reviewed-on: https://gerrit.iotivity.org/gerrit/18955 Tested-by: jenkins-iotivity Reviewed-by: jaehyun Cho Reviewed-by: Ashok Babu Channa --- resource/csdk/connectivity/api/cautilinterface.h | 2 +- .../connectivity/util/inc/caconnectionmanager.h | 2 +- .../util/src/camanager/caconnectionmanager.c | 2 +- .../util/src/camanager/camanagerutil.c | 56 ++++++++++++---------- .../util/src/camanager/camanagerutil.h | 4 +- .../util/src/camanager/camessagearbiter.c | 14 +++--- .../util/src/camanager/camessagearbiter.h | 2 +- .../csdk/connectivity/util/src/cautilinterface.c | 2 +- resource/csdk/stack/src/occonnectionmanager.c | 4 +- 9 files changed, 47 insertions(+), 41 deletions(-) diff --git a/resource/csdk/connectivity/api/cautilinterface.h b/resource/csdk/connectivity/api/cautilinterface.h index 5c460eb..e98c02f 100644 --- a/resource/csdk/connectivity/api/cautilinterface.h +++ b/resource/csdk/connectivity/api/cautilinterface.h @@ -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 diff --git a/resource/csdk/connectivity/util/inc/caconnectionmanager.h b/resource/csdk/connectivity/util/inc/caconnectionmanager.h index 16ef031..f5c15a3 100644 --- a/resource/csdk/connectivity/util/inc/caconnectionmanager.h +++ b/resource/csdk/connectivity/util/inc/caconnectionmanager.h @@ -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. diff --git a/resource/csdk/connectivity/util/src/camanager/caconnectionmanager.c b/resource/csdk/connectivity/util/src/camanager/caconnectionmanager.c index 12e54f3..1a9e5b4 100644 --- a/resource/csdk/connectivity/util/src/camanager/caconnectionmanager.c +++ b/resource/csdk/connectivity/util/src/camanager/caconnectionmanager.c @@ -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); } diff --git a/resource/csdk/connectivity/util/src/camanager/camanagerutil.c b/resource/csdk/connectivity/util/src/camanager/camanagerutil.c index b6844fd..f12c715 100644 --- a/resource/csdk/connectivity/util/src/camanager/camanagerutil.c +++ b/resource/csdk/connectivity/util/src/camanager/camanagerutil.c @@ -23,6 +23,7 @@ #include #include #include +#include #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; diff --git a/resource/csdk/connectivity/util/src/camanager/camanagerutil.h b/resource/csdk/connectivity/util/src/camanager/camanagerutil.h index 6aff40f..adf41cd 100644 --- a/resource/csdk/connectivity/util/src/camanager/camanagerutil.h +++ b/resource/csdk/connectivity/util/src/camanager/camanagerutil.h @@ -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. diff --git a/resource/csdk/connectivity/util/src/camanager/camessagearbiter.c b/resource/csdk/connectivity/util/src/camanager/camessagearbiter.c index 741ceff..ff5f536 100644 --- a/resource/csdk/connectivity/util/src/camanager/camessagearbiter.c +++ b/resource/csdk/connectivity/util/src/camanager/camessagearbiter.c @@ -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"); diff --git a/resource/csdk/connectivity/util/src/camanager/camessagearbiter.h b/resource/csdk/connectivity/util/src/camanager/camessagearbiter.h index 44ea9b0..c27f308 100644 --- a/resource/csdk/connectivity/util/src/camanager/camessagearbiter.h +++ b/resource/csdk/connectivity/util/src/camanager/camessagearbiter.h @@ -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 diff --git a/resource/csdk/connectivity/util/src/cautilinterface.c b/resource/csdk/connectivity/util/src/cautilinterface.c index 1debea1..8508ba3 100644 --- a/resource/csdk/connectivity/util/src/cautilinterface.c +++ b/resource/csdk/connectivity/util/src/cautilinterface.c @@ -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); } diff --git a/resource/csdk/stack/src/occonnectionmanager.c b/resource/csdk/stack/src/occonnectionmanager.c index c60740d..269378d 100755 --- a/resource/csdk/stack/src/occonnectionmanager.c +++ b/resource/csdk/stack/src/occonnectionmanager.c @@ -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!"); -- 2.7.4