Commit 4b305459 authored by Jaewook Jung's avatar Jaewook Jung Committed by Ashok Babu Channa

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: default avatarJaewook Jung <jw0213.jung@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/18955Tested-by: default avatarjenkins-iotivity <jenkins@iotivity.org>
Reviewed-by: default avatarjaehyun Cho <jaehyun3.cho@samsung.com>
Reviewed-by: default avatarAshok Babu Channa <ashok.channa@samsung.com>
parent 5be2d776
......@@ -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
......
......@@ -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.
......
......@@ -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);
}
......
......@@ -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;
......
......@@ -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.
......
......@@ -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");
......
......@@ -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
......
......@@ -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);
}
......
......@@ -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!");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment