From ea63cd55d8ade049d37bb3cfb7b7b27b4bce0b6d Mon Sep 17 00:00:00 2001 From: Pawel Winogrodzki Date: Mon, 27 Feb 2017 18:37:57 -0800 Subject: [PATCH] IOT-1583: Removing /W3 warnings inside connectivity/ (part 2) Removing the /W3 warnings in order to add the /WX option to prevent new ones from being added inside the resource/csdk/connectivity/ directory. Change-Id: I13cd0b6058693432e3eb57f4bf7a1bfa0fa6f015 Signed-off-by: Pawel Winogrodzki Reviewed-on: https://gerrit.iotivity.org/gerrit/17547 Tested-by: jenkins-iotivity Reviewed-by: Dan Mihai Reviewed-by: Dave Thaler --- resource/csdk/connectivity/inc/caedradapter.h | 2 +- .../connectivity/inc/caedradapter_singlethread.h | 2 +- resource/csdk/connectivity/inc/caipadapter.h | 2 +- resource/csdk/connectivity/inc/caipinterface.h | 6 +- resource/csdk/connectivity/inc/canfcadapter.h | 2 +- resource/csdk/connectivity/inc/canfcinterface.h | 2 +- resource/csdk/connectivity/inc/caraadapter.h | 2 +- resource/csdk/connectivity/inc/catcpadapter.h | 8 +- .../src/ip_adapter/android/caipnwmonitor.c | 4 +- .../src/ip_adapter/arduino/caipclient_eth.cpp | 6 +- .../src/ip_adapter/arduino/caipclient_wifi.cpp | 6 +- .../src/ip_adapter/arduino/caipserver_eth.cpp | 6 +- .../src/ip_adapter/arduino/caipserver_wifi.cpp | 6 +- .../csdk/connectivity/src/ip_adapter/caipadapter.c | 8 +- .../csdk/connectivity/src/ip_adapter/caipserver.c | 108 ++++++++++++--------- .../src/ip_adapter/linux/caipnwmonitor.c | 29 ++++-- .../src/ip_adapter/windows/caipnwmonitor.c | 18 ++-- .../src/tcp_adapter/arduino/catcpserver_eth.cpp | 4 +- .../connectivity/src/tcp_adapter/catcpadapter.c | 29 +++--- .../connectivity/src/tcp_adapter/catcpserver.c | 40 +++++--- resource/csdk/stack/src/ocpayload.c | 4 - 21 files changed, 167 insertions(+), 127 deletions(-) diff --git a/resource/csdk/connectivity/inc/caedradapter.h b/resource/csdk/connectivity/inc/caedradapter.h index 019f363..0b45d35 100644 --- a/resource/csdk/connectivity/inc/caedradapter.h +++ b/resource/csdk/connectivity/inc/caedradapter.h @@ -122,7 +122,7 @@ int32_t CASendEDRMulticastData(const CAEndpoint_t *endpoint, const void *data, * * @return ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h). */ -CAResult_t CAGetEDRInterfaceInformation(CAEndpoint_t **info, uint32_t *size); +CAResult_t CAGetEDRInterfaceInformation(CAEndpoint_t **info, size_t *size); /** * Read Synchronous API callback. diff --git a/resource/csdk/connectivity/inc/caedradapter_singlethread.h b/resource/csdk/connectivity/inc/caedradapter_singlethread.h index f1cba26..84bd3d3 100644 --- a/resource/csdk/connectivity/inc/caedradapter_singlethread.h +++ b/resource/csdk/connectivity/inc/caedradapter_singlethread.h @@ -129,7 +129,7 @@ int32_t CASendEDRMulticastData(const void *data, uint32_t dataLength); * @retval #CA_STATUS_FAILED Operation failed * @remarks info is allocated in this API and should be freed by the caller. */ -CAResult_t CAGetEDRInterfaceInformation(CAEndpoint_t **info, uint32_t *size); +CAResult_t CAGetEDRInterfaceInformation(CAEndpoint_t **info, size_t *size); /** * @brief Read Synchronous API callback. diff --git a/resource/csdk/connectivity/inc/caipadapter.h b/resource/csdk/connectivity/inc/caipadapter.h index 829b043..f1e128f 100644 --- a/resource/csdk/connectivity/inc/caipadapter.h +++ b/resource/csdk/connectivity/inc/caipadapter.h @@ -119,7 +119,7 @@ int32_t CASendIPMulticastData(const CAEndpoint_t *endpoint, const void *data, * @param[out] size Number of local connectivity structures. * @return ::CA_STATUS_OK or Appropriate error code. */ -CAResult_t CAGetIPInterfaceInformation(CAEndpoint_t **info, uint32_t *size); +CAResult_t CAGetIPInterfaceInformation(CAEndpoint_t **info, size_t *size); /** * Read Synchronous API callback. diff --git a/resource/csdk/connectivity/inc/caipinterface.h b/resource/csdk/connectivity/inc/caipinterface.h index e08d7f0..bcf1573 100644 --- a/resource/csdk/connectivity/inc/caipinterface.h +++ b/resource/csdk/connectivity/inc/caipinterface.h @@ -57,7 +57,7 @@ typedef enum */ typedef void (*CAIPPacketReceivedCallback)(const CASecureEndpoint_t *sep, const void *data, - uint32_t dataLength); + size_t dataLength); /** * Callback to notify error in the IP adapter. @@ -69,7 +69,7 @@ typedef void (*CAIPPacketReceivedCallback)(const CASecureEndpoint_t *sep, * @pre Callback must be registered using CAIPSetPacketReceiveCallback(). */ typedef void (*CAIPErrorHandleCallback)(const CAEndpoint_t *endpoint, const void *data, - uint32_t dataLength, CAResult_t result); + size_t dataLength, CAResult_t result); /** * Start IP server. @@ -147,7 +147,7 @@ void CAIPSetUnicastPort(uint16_t port); */ void CAIPSendData(CAEndpoint_t *endpoint, const void *data, - uint32_t dataLength, + size_t dataLength, bool isMulticast); /** diff --git a/resource/csdk/connectivity/inc/canfcadapter.h b/resource/csdk/connectivity/inc/canfcadapter.h index ba308db..0a3e597 100644 --- a/resource/csdk/connectivity/inc/canfcadapter.h +++ b/resource/csdk/connectivity/inc/canfcadapter.h @@ -107,7 +107,7 @@ int32_t CASendNFCMulticastData(const CAEndpoint_t *endpoint, const void *data, * @return ::CA_STATUS_OK, if success or Appropriate error code. * @remarks info is allocated in this API and must be freed by the caller. */ -CAResult_t CAGetNFCInterfaceInformation(CAEndpoint_t **info, uint32_t *size); +CAResult_t CAGetNFCInterfaceInformation(CAEndpoint_t **info, size_t *size); /** * Read Synchronous API callback. diff --git a/resource/csdk/connectivity/inc/canfcinterface.h b/resource/csdk/connectivity/inc/canfcinterface.h index 8cbd642..873f755 100644 --- a/resource/csdk/connectivity/inc/canfcinterface.h +++ b/resource/csdk/connectivity/inc/canfcinterface.h @@ -65,7 +65,7 @@ typedef void (*CANFCPacketReceivedCallback)(const CASecureEndpoint_t *endpoint, * @param[in] result result of request. */ typedef void (*CANFCErrorHandleCallback)(const CAEndpoint_t *endpoint, const void *data, - uint32_t dataLength, CAResult_t result); + size_t dataLength, CAResult_t result); /** * Callback to be notified when exception occures on multicast/unicast server. diff --git a/resource/csdk/connectivity/inc/caraadapter.h b/resource/csdk/connectivity/inc/caraadapter.h index 95961de..e93d813 100644 --- a/resource/csdk/connectivity/inc/caraadapter.h +++ b/resource/csdk/connectivity/inc/caraadapter.h @@ -82,7 +82,7 @@ int32_t CASendRAUnicastData(const CAEndpoint_t *endpoint, const void *data, * @param[out] size Number of local connectivity structures. * @return ::CA_STATUS_OK or Appropriate error code. */ -CAResult_t CAGetRAInterfaceInformation(CAEndpoint_t **info, uint32_t *size); +CAResult_t CAGetRAInterfaceInformation(CAEndpoint_t **info, size_t *size); /** * Stops RA server and de-register XMPP callback listeners. diff --git a/resource/csdk/connectivity/inc/catcpadapter.h b/resource/csdk/connectivity/inc/catcpadapter.h index eb232dd..c70a08a 100644 --- a/resource/csdk/connectivity/inc/catcpadapter.h +++ b/resource/csdk/connectivity/inc/catcpadapter.h @@ -60,7 +60,7 @@ typedef enum typedef struct CATCPSessionInfo_t { CASecureEndpoint_t sep; /**< secure endpoint information */ - int fd; /**< file descriptor info */ + CASocketFd_t fd; /**< file descriptor info */ unsigned char* data; /**< received data from remote device */ size_t len; /**< received data length */ size_t totalLen; /**< total coap data length required to receive */ @@ -135,7 +135,7 @@ CAResult_t CAStartTCPDiscoveryServer(); * @param[in] data Data which is required to be sent. * @param[in] dataLen Size of data to be sent. * @param[in] dataType Data type which is REQUEST or RESPONSE. - * @note dataLen must be > 0. + * @note dataLen must be > 0 and <= INT_MAX. * @return The number of bytes sent on the network, or -1 upon error. */ int32_t CASendTCPUnicastData(const CAEndpoint_t *endpoint, @@ -149,7 +149,7 @@ int32_t CASendTCPUnicastData(const CAEndpoint_t *endpoint, * @param[in] data Data which is required to be sent. * @param[in] dataLen Size of data to be sent. * @param[in] dataType Data type which is REQUEST or RESPONSE. - * @note dataLen must be > 0. + * @note dataLen must be > 0 and <= INT_MAX. * @return The number of bytes sent on the network, or -1 upon error. */ int32_t CASendTCPMulticastData(const CAEndpoint_t *endpoint, @@ -163,7 +163,7 @@ int32_t CASendTCPMulticastData(const CAEndpoint_t *endpoint, * @param[out] size Number of local connectivity structures. * @return ::CA_STATUS_OK or Appropriate error code. */ -CAResult_t CAGetTCPInterfaceInformation(CAEndpoint_t **info, uint32_t *size); +CAResult_t CAGetTCPInterfaceInformation(CAEndpoint_t **info, size_t *size); /** * Read Synchronous API callback. diff --git a/resource/csdk/connectivity/src/ip_adapter/android/caipnwmonitor.c b/resource/csdk/connectivity/src/ip_adapter/android/caipnwmonitor.c index 44965c7..3dfbc6d 100644 --- a/resource/csdk/connectivity/src/ip_adapter/android/caipnwmonitor.c +++ b/resource/csdk/connectivity/src/ip_adapter/android/caipnwmonitor.c @@ -491,8 +491,8 @@ Java_org_iotivity_ca_CaIpInterface_caIpStateEnabled(JNIEnv *env, jclass class) return; } - uint32_t listLength = u_arraylist_length(iflist); - for (uint32_t i = 0; i < listLength; i++) + size_t listLength = u_arraylist_length(iflist); + for (size_t i = 0; i < listLength; i++) { CAInterface_t *ifitem = (CAInterface_t *)u_arraylist_get(iflist, i); if (!ifitem) diff --git a/resource/csdk/connectivity/src/ip_adapter/arduino/caipclient_eth.cpp b/resource/csdk/connectivity/src/ip_adapter/arduino/caipclient_eth.cpp index f36778f..879f500 100644 --- a/resource/csdk/connectivity/src/ip_adapter/arduino/caipclient_eth.cpp +++ b/resource/csdk/connectivity/src/ip_adapter/arduino/caipclient_eth.cpp @@ -38,6 +38,8 @@ #define TAG "IPC" +#define UINT16_MAX 65535 + static int g_sockID = 0; /** @@ -73,7 +75,7 @@ void CAIPSetUnicastPort(uint16_t port) } void CAIPSendData(CAEndpoint_t *endpoint, const void *buf, - uint32_t bufLen, bool isMulticast) + size_t bufLen, bool isMulticast) { if (!isMulticast && 0 == g_unicastPort) { @@ -125,7 +127,7 @@ void CAIPSendData(CAEndpoint_t *endpoint, const void *buf, return; } - if (bufLen > 65535) // Max value for uint16_t + if (bufLen > UINT16_MAX) { // This will never happen as max buffer size we are dealing with is COAP_MAX_PDU_SIZE OIC_LOG(ERROR, TAG, "Size exceeded"); diff --git a/resource/csdk/connectivity/src/ip_adapter/arduino/caipclient_wifi.cpp b/resource/csdk/connectivity/src/ip_adapter/arduino/caipclient_wifi.cpp index 9dda5aa..b1fa9c7 100644 --- a/resource/csdk/connectivity/src/ip_adapter/arduino/caipclient_wifi.cpp +++ b/resource/csdk/connectivity/src/ip_adapter/arduino/caipclient_wifi.cpp @@ -50,7 +50,7 @@ void CAIPSetUnicastPort(uint16_t port) } void CAIPSendData(CAEndpoint_t *endpoint, - const void *data, uint32_t dataLength, bool isMulticast) + const void *data, size_t dataLength, bool isMulticast) { OIC_LOG(DEBUG, TAG, "IN"); @@ -73,7 +73,7 @@ void CAIPSendData(CAEndpoint_t *endpoint, IPAddress remoteIp(ip); Udp.beginPacket(remoteIp, endpoint->port); - uint32_t bytesWritten = 0; + size_t bytesWritten = 0; while (bytesWritten < dataLength) { // get remaining bytes @@ -85,7 +85,7 @@ void CAIPSendData(CAEndpoint_t *endpoint, if(writeCount == 0) { // write failed - OIC_LOG_V(ERROR, TAG, "Failed after %u", bytesWritten); + OIC_LOG_V(ERROR, TAG, "Failed after %" PRIuPTR, bytesWritten); break; } bytesWritten += writeCount; diff --git a/resource/csdk/connectivity/src/ip_adapter/arduino/caipserver_eth.cpp b/resource/csdk/connectivity/src/ip_adapter/arduino/caipserver_eth.cpp index d38ef07..4dd0e60 100644 --- a/resource/csdk/connectivity/src/ip_adapter/arduino/caipserver_eth.cpp +++ b/resource/csdk/connectivity/src/ip_adapter/arduino/caipserver_eth.cpp @@ -332,7 +332,7 @@ void CAIPPullData() CAArduinoCheckData(); } -CAResult_t CAGetIPInterfaceInformation(CAEndpoint_t **info, uint32_t *size) +CAResult_t CAGetIPInterfaceInformation(CAEndpoint_t **info, size_t *size) { OIC_LOG(DEBUG, TAG, "IN"); @@ -346,7 +346,7 @@ CAResult_t CAGetIPInterfaceInformation(CAEndpoint_t **info, uint32_t *size) return CA_STATUS_FAILED; } - uint32_t len = u_arraylist_length(iflist); + size_t len = u_arraylist_length(iflist); CAEndpoint_t *eps = (CAEndpoint_t *)OICCalloc(len, sizeof (CAEndpoint_t)); if (!eps) @@ -356,7 +356,7 @@ CAResult_t CAGetIPInterfaceInformation(CAEndpoint_t **info, uint32_t *size) return CA_MEMORY_ALLOC_FAILED; } - for (uint32_t i = 0, j = 0; i < len; i++) + for (size_t i = 0, j = 0; i < len; i++) { CAInterface_t *ifitem = (CAInterface_t *)u_arraylist_get(iflist, i); if(!ifitem) diff --git a/resource/csdk/connectivity/src/ip_adapter/arduino/caipserver_wifi.cpp b/resource/csdk/connectivity/src/ip_adapter/arduino/caipserver_wifi.cpp index bd63d98..98adcbb 100644 --- a/resource/csdk/connectivity/src/ip_adapter/arduino/caipserver_wifi.cpp +++ b/resource/csdk/connectivity/src/ip_adapter/arduino/caipserver_wifi.cpp @@ -269,7 +269,7 @@ void CAIPPullData() CAArduinoCheckData(); } -CAResult_t CAGetIPInterfaceInformation(CAEndpoint_t **info, uint32_t *size) +CAResult_t CAGetIPInterfaceInformation(CAEndpoint_t **info, size_t *size) { OIC_LOG(DEBUG, TAG, "IN"); @@ -283,7 +283,7 @@ CAResult_t CAGetIPInterfaceInformation(CAEndpoint_t **info, uint32_t *size) return CA_STATUS_FAILED; } - uint32_t len = u_arraylist_length(iflist); + size_t len = u_arraylist_length(iflist); CAEndpoint_t *eps = (CAEndpoint_t *)OICCalloc(len, sizeof (CAEndpoint_t)); if (!eps) @@ -293,7 +293,7 @@ CAResult_t CAGetIPInterfaceInformation(CAEndpoint_t **info, uint32_t *size) return CA_MEMORY_ALLOC_FAILED; } - for (uint32_t i = 0, j = 0; i < len; i++) + for (size_t i = 0, j = 0; i < len; i++) { CAInterface_t *ifitem = (CAInterface_t *)u_arraylist_get(iflist, i); if(!ifitem) diff --git a/resource/csdk/connectivity/src/ip_adapter/caipadapter.c b/resource/csdk/connectivity/src/ip_adapter/caipadapter.c index 876ba23..91cdfd8 100644 --- a/resource/csdk/connectivity/src/ip_adapter/caipadapter.c +++ b/resource/csdk/connectivity/src/ip_adapter/caipadapter.c @@ -188,7 +188,7 @@ static void CAUpdateStoredIPAddressInfo(CANetworkStatus_t status) OIC_LOG(DEBUG, TAG, "IP adapter status is on. Store the own IP address info"); CAEndpoint_t *eps = NULL; - uint32_t numOfEps = 0; + size_t numOfEps = 0; CAResult_t res = CAGetIPInterfaceInformation(&eps, &numOfEps); if (CA_STATUS_OK != res) @@ -210,8 +210,8 @@ static void CAUpdateStoredIPAddressInfo(CANetworkStatus_t status) OICFree(headEp); headEp = NULL; - uint32_t len = u_arraylist_length(g_ownIpEndpointList); - for (uint32_t i = len; i > 0; i--) + size_t len = u_arraylist_length(g_ownIpEndpointList); + for (size_t i = len; i > 0; i--) { u_arraylist_remove(g_ownIpEndpointList, i - 1); } @@ -269,7 +269,7 @@ bool CAIPIsLocalEndpoint(const CAEndpoint_t *ep) } void CAIPErrorHandler(const CAEndpoint_t *endpoint, const void *data, - uint32_t dataLength, CAResult_t result) + size_t dataLength, CAResult_t result) { VERIFY_NON_NULL_VOID(endpoint, TAG, "endpoint is NULL"); VERIFY_NON_NULL_VOID(data, TAG, "data is NULL"); diff --git a/resource/csdk/connectivity/src/ip_adapter/caipserver.c b/resource/csdk/connectivity/src/ip_adapter/caipserver.c index cde643b..542be30 100644 --- a/resource/csdk/connectivity/src/ip_adapter/caipserver.c +++ b/resource/csdk/connectivity/src/ip_adapter/caipserver.c @@ -257,8 +257,8 @@ static void CASelectReturned(fd_set *readFds, int ret) u_arraylist_t *iflist = CAFindInterfaceChange(); if (iflist) { - uint32_t listLength = u_arraylist_length(iflist); - for (uint32_t i = 0; i < listLength; i++) + size_t listLength = u_arraylist_length(iflist); + for (size_t i = 0; i < listLength; i++) { CAInterface_t *ifitem = (CAInterface_t *)u_arraylist_get(iflist, i); if (ifitem) @@ -357,8 +357,8 @@ static void CAFindReadyMessage() { CASocketFd_t socketArray[EVENT_ARRAY_SIZE]; HANDLE eventArray[EVENT_ARRAY_SIZE]; - int arraySize = 0; - int eventIndex; + DWORD arraySize = 0; + DWORD eventIndex; // socketArray and eventArray should have same number of elements OC_STATIC_ASSERT(_countof(socketArray) == _countof(eventArray), "Arrays should have same number of elements"); @@ -393,7 +393,7 @@ static void CAFindReadyMessage() while (!caglobals.ip.terminate) { - int ret = WSAWaitForMultipleEvents(arraySize, eventArray, FALSE, WSA_INFINITE, FALSE); + DWORD ret = WSAWaitForMultipleEvents(arraySize, eventArray, FALSE, WSA_INFINITE, FALSE); assert(ret >= WSA_WAIT_EVENT_0); assert(ret < (WSA_WAIT_EVENT_0 + arraySize)); @@ -424,8 +424,8 @@ static void CAFindReadyMessage() u_arraylist_t *iflist = CAFindInterfaceChange(); if (iflist) { - uint32_t listLength = u_arraylist_length(iflist); - for (uint32_t i = 0; i < listLength; i++) + size_t listLength = u_arraylist_length(iflist); + for (size_t i = 0; i < listLength; i++) { CAInterface_t *ifitem = (CAInterface_t *)u_arraylist_get(iflist, i); if (ifitem) @@ -455,7 +455,7 @@ static void CAFindReadyMessage() } - for (int i = 0; i < arraySize; i++) + for (size_t i = 0; i < arraySize; i++) { HANDLE h = eventArray[i]; if (h != caglobals.ip.addressChangeEvent) @@ -697,8 +697,8 @@ static CAResult_t CAReceiveMessage(CASocketFd_t fd, CATransportFlags_t flags) void CAIPPullData() { - OIC_LOG(DEBUG, TAG, "IN"); - OIC_LOG(DEBUG, TAG, "OUT"); + OIC_LOG_V(DEBUG, TAG, "IN %s", __func__); + OIC_LOG_V(DEBUG, TAG, "OUT %s", __func__); } static CASocketFd_t CACreateSocket(int family, uint16_t *port, bool isMulticast) @@ -797,21 +797,29 @@ static CASocketFd_t CACreateSocket(int family, uint16_t *port, bool isMulticast) #define CHECKFD(FD) #else #define CHECKFD(FD) \ +do \ +{ \ if (FD > caglobals.ip.maxfd) \ - caglobals.ip.maxfd = FD; + { \ + caglobals.ip.maxfd = FD; \ + } \ +} while (0) #endif - #define NEWSOCKET(FAMILY, NAME, MULTICAST) \ +do \ +{ \ caglobals.ip.NAME.fd = CACreateSocket(FAMILY, &caglobals.ip.NAME.port, MULTICAST); \ if (caglobals.ip.NAME.fd == OC_INVALID_SOCKET) \ { \ caglobals.ip.NAME.port = 0; \ caglobals.ip.NAME.fd = CACreateSocket(FAMILY, &caglobals.ip.NAME.port, MULTICAST); \ } \ - CHECKFD(caglobals.ip.NAME.fd) + CHECKFD(caglobals.ip.NAME.fd); \ +} while(0) static void CARegisterForAddressChanges() { + OIC_LOG_V(DEBUG, TAG, "IN %s", __func__); #ifdef _WIN32 caglobals.ip.addressChangeEvent = WSACreateEvent(); if (WSA_INVALID_EVENT != caglobals.ip.addressChangeEvent) @@ -846,10 +854,12 @@ static void CARegisterForAddressChanges() } #endif #endif + OIC_LOG_V(DEBUG, TAG, "OUT %s", __func__); } static void CAInitializeFastShutdownMechanism() { + OIC_LOG_V(DEBUG, TAG, "IN %s", __func__); caglobals.ip.selectTimeout = -1; // don't poll for shutdown int ret = -1; #if defined(WSA_WAIT_EVENT_0) @@ -895,6 +905,7 @@ static void CAInitializeFastShutdownMechanism() OIC_LOG_V(ERROR, TAG, "fast shutdown mechanism init failed: %s", CAIPS_GET_ERROR); caglobals.ip.selectTimeout = SELECT_TIMEOUT; //poll needed for shutdown } + OIC_LOG_V(DEBUG, TAG, "OUT %s", __func__); } CAResult_t CAIPStartServer(const ca_thread_pool_t threadPool) @@ -935,18 +946,18 @@ CAResult_t CAIPStartServer(const ca_thread_pool_t threadPool) if (caglobals.ip.ipv6enabled) { - NEWSOCKET(AF_INET6, u6, false) - NEWSOCKET(AF_INET6, u6s, false) - NEWSOCKET(AF_INET6, m6, true) - NEWSOCKET(AF_INET6, m6s, true) + NEWSOCKET(AF_INET6, u6, false); + NEWSOCKET(AF_INET6, u6s, false); + NEWSOCKET(AF_INET6, m6, true); + NEWSOCKET(AF_INET6, m6s, true); OIC_LOG_V(INFO, TAG, "IPv6 unicast port: %u", caglobals.ip.u6.port); } if (caglobals.ip.ipv4enabled) { - NEWSOCKET(AF_INET, u4, false) - NEWSOCKET(AF_INET, u4s, false) - NEWSOCKET(AF_INET, m4, true) - NEWSOCKET(AF_INET, m4s, true) + NEWSOCKET(AF_INET, u4, false); + NEWSOCKET(AF_INET, u4s, false); + NEWSOCKET(AF_INET, m4, true); + NEWSOCKET(AF_INET, m4s, true); OIC_LOG_V(INFO, TAG, "IPv4 unicast port: %u", caglobals.ip.u4.port); } @@ -1100,7 +1111,7 @@ static void applyMulticastToInterface4(uint32_t ifindex) } } -static void applyMulticast6(int fd, struct in6_addr *addr, uint32_t ifindex) +static void applyMulticast6(CASocketFd_t fd, struct in6_addr *addr, uint32_t ifindex) { struct ipv6_mreq mreq = { .ipv6mr_interface = ifindex }; @@ -1155,6 +1166,7 @@ static void applyMulticastToInterface6(uint32_t ifindex) CAResult_t CAIPStartListenServer() { + OIC_LOG_V(DEBUG, TAG, "IN %s", __func__); u_arraylist_t *iflist = CAIPGetInterfaceInformation(0); if (!iflist) { @@ -1162,10 +1174,10 @@ CAResult_t CAIPStartListenServer() return CA_STATUS_FAILED; } - uint32_t len = u_arraylist_length(iflist); + size_t len = u_arraylist_length(iflist); OIC_LOG_V(DEBUG, TAG, "IP network interfaces found: %d", len); - for (uint32_t i = 0; i < len; i++) + for (size_t i = 0; i < len; i++) { CAInterface_t *ifitem = (CAInterface_t *)u_arraylist_get(iflist, i); @@ -1190,6 +1202,7 @@ CAResult_t CAIPStartListenServer() } u_arraylist_destroy(iflist); + OIC_LOG_V(DEBUG, TAG, "OUT %s", __func__); return CA_STATUS_OK; } @@ -1202,10 +1215,10 @@ CAResult_t CAIPStopListenServer() return CA_STATUS_FAILED; } - uint32_t len = u_arraylist_length(iflist); + size_t len = u_arraylist_length(iflist); OIC_LOG_V(DEBUG, TAG, "IP network interfaces found: %d", len); - for (uint32_t i = 0; i < len; i++) + for (size_t i = 0; i < len; i++) { CAInterface_t *ifitem = (CAInterface_t *)u_arraylist_get(iflist, i); @@ -1259,11 +1272,11 @@ void CAIPSetPacketReceiveCallback(CAIPPacketReceivedCallback callback) g_packetReceivedCallback = callback; } -static void sendData(int fd, const CAEndpoint_t *endpoint, - const void *data, uint32_t dlen, +static void sendData(CASocketFd_t fd, const CAEndpoint_t *endpoint, + const void *data, size_t dlen, const char *cast, const char *fam) { - OIC_LOG(DEBUG, TAG, "IN"); + OIC_LOG_V(DEBUG, TAG, "IN %s", __func__); if (!endpoint) { @@ -1316,9 +1329,10 @@ static void sendData(int fd, const CAEndpoint_t *endpoint, #else int err = 0; int len = 0; - int sent = 0; + size_t sent = 0; do { - len = sendto(fd, ((char*)data) + sent, dlen - sent, 0, (struct sockaddr *)&sock, socklen); + int dataToSend = ((dlen - sent) > INT_MAX) ? INT_MAX : (int)(dlen - sent); + len = sendto(fd, ((char*)data) + sent, dataToSend, 0, (struct sockaddr *)&sock, socklen); if (OC_SOCKET_ERROR == len) { err = WSAGetLastError(); @@ -1340,9 +1354,9 @@ static void sendData(int fd, const CAEndpoint_t *endpoint, { OIC_LOG_V(DEBUG, TAG, "%s%s %s sendTo (Partial Send) is successful: " "currently sent: %ld bytes, " - "total sent: %ld bytes, " - "remaining: %ld bytes", - secure, cast, fam, len, sent, dlen-sent); + "total sent: %" PRIuPTR " bytes, " + "remaining: %" PRIuPTR " bytes", + secure, cast, fam, len, sent, (dlen - sent)); } else { @@ -1356,7 +1370,7 @@ static void sendData(int fd, const CAEndpoint_t *endpoint, static void sendMulticastData6(const u_arraylist_t *iflist, CAEndpoint_t *endpoint, - const void *data, uint32_t datalen) + const void *data, size_t datalen) { if (!endpoint) { @@ -1372,10 +1386,10 @@ static void sendMulticastData6(const u_arraylist_t *iflist, return; } OICStrcpy(endpoint->addr, sizeof(endpoint->addr), ipv6mcname); - int fd = caglobals.ip.u6.fd; + CASocketFd_t fd = caglobals.ip.u6.fd; - uint32_t len = u_arraylist_length(iflist); - for (uint32_t i = 0; i < len; i++) + size_t len = u_arraylist_length(iflist); + for (size_t i = 0; i < len; i++) { CAInterface_t *ifitem = (CAInterface_t *)u_arraylist_get(iflist, i); if (!ifitem) @@ -1403,7 +1417,7 @@ static void sendMulticastData6(const u_arraylist_t *iflist, static void sendMulticastData4(const u_arraylist_t *iflist, CAEndpoint_t *endpoint, - const void *data, uint32_t datalen) + const void *data, size_t datalen) { VERIFY_NON_NULL_VOID(endpoint, TAG, "endpoint is NULL"); @@ -1417,10 +1431,10 @@ static void sendMulticastData4(const u_arraylist_t *iflist, #endif OICStrcpy(endpoint->addr, sizeof(endpoint->addr), IPv4_MULTICAST); - int fd = caglobals.ip.u4.fd; + CASocketFd_t fd = caglobals.ip.u4.fd; - uint32_t len = u_arraylist_length(iflist); - for (uint32_t i = 0; i < len; i++) + size_t len = u_arraylist_length(iflist); + for (size_t i = 0; i < len; i++) { CAInterface_t *ifitem = (CAInterface_t *)u_arraylist_get(iflist, i); if (!ifitem) @@ -1449,7 +1463,7 @@ static void sendMulticastData4(const u_arraylist_t *iflist, } } -void CAIPSendData(CAEndpoint_t *endpoint, const void *data, uint32_t datalen, +void CAIPSendData(CAEndpoint_t *endpoint, const void *data, size_t datalen, bool isMulticast) { VERIFY_NON_NULL_VOID(endpoint, TAG, "endpoint is NULL"); @@ -1506,7 +1520,7 @@ void CAIPSendData(CAEndpoint_t *endpoint, const void *data, uint32_t datalen, } } -CAResult_t CAGetIPInterfaceInformation(CAEndpoint_t **info, uint32_t *size) +CAResult_t CAGetIPInterfaceInformation(CAEndpoint_t **info, size_t *size) { VERIFY_NON_NULL(info, TAG, "info is NULL"); VERIFY_NON_NULL(size, TAG, "size is NULL"); @@ -1518,8 +1532,8 @@ CAResult_t CAGetIPInterfaceInformation(CAEndpoint_t **info, uint32_t *size) return CA_STATUS_FAILED; } - uint32_t len = u_arraylist_length(iflist); - uint32_t length = len; + size_t len = u_arraylist_length(iflist); + size_t length = len; #ifdef __WITH_DTLS__ //If DTLS is supported, each interface can support secure port as well @@ -1534,7 +1548,7 @@ CAResult_t CAGetIPInterfaceInformation(CAEndpoint_t **info, uint32_t *size) return CA_MEMORY_ALLOC_FAILED; } - for (uint32_t i = 0, j = 0; i < len; i++) + for (size_t i = 0, j = 0; i < len; i++) { CAInterface_t *ifitem = (CAInterface_t *)u_arraylist_get(iflist, i); if(!ifitem) diff --git a/resource/csdk/connectivity/src/ip_adapter/linux/caipnwmonitor.c b/resource/csdk/connectivity/src/ip_adapter/linux/caipnwmonitor.c index d86a854..596b4a7 100644 --- a/resource/csdk/connectivity/src/ip_adapter/linux/caipnwmonitor.c +++ b/resource/csdk/connectivity/src/ip_adapter/linux/caipnwmonitor.c @@ -142,6 +142,8 @@ static void CAIPDestroyNetworkMonitorList() static bool CACmpNetworkList(uint32_t ifiindex) { + OIC_LOG_V(DEBUG, TAG, "IN %s: ifiindex = %ul", __func__, ifiindex); + if (!g_netInterfaceList) { OIC_LOG(ERROR, TAG, "g_netInterfaceList is NULL"); @@ -150,8 +152,8 @@ static bool CACmpNetworkList(uint32_t ifiindex) oc_mutex_lock(g_networkMonitorContextMutex); - uint32_t list_length = u_arraylist_length(g_netInterfaceList); - for (uint32_t list_index = 0; list_index < list_length; list_index++) + size_t list_length = u_arraylist_length(g_netInterfaceList); + for (size_t list_index = 0; list_index < list_length; list_index++) { CAInterface_t *currItem = (CAInterface_t *) u_arraylist_get(g_netInterfaceList, list_index); @@ -162,11 +164,13 @@ static bool CACmpNetworkList(uint32_t ifiindex) } } oc_mutex_unlock(g_networkMonitorContextMutex); + OIC_LOG_V(DEBUG, TAG, "OUT %s", __func__); return false; } static CAResult_t CAAddNetworkMonitorList(CAInterface_t *ifitem) { + OIC_LOG_V(DEBUG, TAG, "IN %s", __func__); VERIFY_NON_NULL(g_netInterfaceList, TAG, "g_netInterfaceList is NULL"); VERIFY_NON_NULL(ifitem, TAG, "ifitem is NULL"); @@ -179,6 +183,7 @@ static CAResult_t CAAddNetworkMonitorList(CAInterface_t *ifitem) return CA_STATUS_FAILED; } oc_mutex_unlock(g_networkMonitorContextMutex); + OIC_LOG_V(DEBUG, TAG, "OUT %s", __func__); return CA_STATUS_OK; } @@ -188,8 +193,8 @@ static void CARemoveNetworkMonitorList(int ifiindex) oc_mutex_lock(g_networkMonitorContextMutex); - uint32_t list_length = u_arraylist_length(g_netInterfaceList); - for (uint32_t list_index = 0; list_index < list_length; list_index++) + size_t list_length = u_arraylist_length(g_netInterfaceList); + for (size_t list_index = 0; list_index < list_length; list_index++) { CAInterface_t *removedifitem = (CAInterface_t *) u_arraylist_get( g_netInterfaceList, list_index); @@ -232,6 +237,7 @@ int CAGetPollingInterval(int interval) static void CAIPPassNetworkChangesToAdapter(CANetworkStatus_t status) { + OIC_LOG_V(DEBUG, TAG, "IN %s: status = %d", __func__, status); CAIPCBData_t *cbitem = NULL; LL_FOREACH(g_adapterCallbackList, cbitem) { @@ -241,6 +247,7 @@ static void CAIPPassNetworkChangesToAdapter(CANetworkStatus_t status) CALogAdapterStateInfo(cbitem->adapter, status); } } + OIC_LOG_V(DEBUG, TAG, "OUT %s", __func__); } CAResult_t CAIPSetNetworkMonitorCallback(CAIPAdapterStateChangeCallback callback, @@ -296,6 +303,9 @@ CAResult_t CAIPUnSetNetworkMonitorCallback(CATransportAdapter_t adapter) static CAInterface_t *CANewInterfaceItem(int index, const char *name, int family, const char *addr, int flags) { + OIC_LOG_V(DEBUG, TAG, "IN %s:" + "index = %d, name = \"%s\", family = %d, addr = \"%s\", flags = %d", + __func__, index, name, family, addr, flags); CAInterface_t *ifitem = (CAInterface_t *)OICCalloc(1, sizeof (CAInterface_t)); if (!ifitem) { @@ -309,6 +319,7 @@ static CAInterface_t *CANewInterfaceItem(int index, const char *name, int family OICStrcpy(ifitem->addr, sizeof (ifitem->addr), addr); ifitem->flags = flags; + OIC_LOG_V(DEBUG, TAG, "OUT %s", __func__); return ifitem; } @@ -370,6 +381,7 @@ u_arraylist_t *CAFindInterfaceChange() u_arraylist_t *CAIPGetInterfaceInformation(int desiredIndex) { + OIC_LOG_V(DEBUG, TAG, "IN %s: desiredIndex = %d", __func__, desiredIndex); if (desiredIndex < 0) { OIC_LOG_V(ERROR, TAG, "invalid index : %d", desiredIndex); @@ -392,6 +404,7 @@ u_arraylist_t *CAIPGetInterfaceInformation(int desiredIndex) } struct ifaddrs *ifa = NULL; + OIC_LOG(DEBUG, TAG, "Iterating over interface addresses."); for (ifa = ifp; ifa; ifa = ifa->ifa_next) { if (!ifa->ifa_addr) @@ -410,10 +423,12 @@ u_arraylist_t *CAIPGetInterfaceInformation(int desiredIndex) continue; } - int length = u_arraylist_length(iflist); + size_t length = u_arraylist_length(iflist); int already = false; - for (int i = length-1; i >= 0; i--) + OIC_LOG_V(DEBUG, TAG, "Iterating over %" PRIuPTR " interfaces.", length); + for (size_t i = 0; i < length; i++) { + OIC_LOG_V(DEBUG, TAG, "Checking interface %" PRIuPTR ".", i); CAInterface_t *ifitem = (CAInterface_t *)u_arraylist_get(iflist, i); if (ifitem @@ -477,11 +492,13 @@ u_arraylist_t *CAIPGetInterfaceInformation(int desiredIndex) } } freeifaddrs(ifp); + OIC_LOG_V(DEBUG, TAG, "OUT %s", __func__); return iflist; exit: freeifaddrs(ifp); u_arraylist_destroy(iflist); + OIC_LOG_V(DEBUG, TAG, "OUT %s", __func__); return NULL; } diff --git a/resource/csdk/connectivity/src/ip_adapter/windows/caipnwmonitor.c b/resource/csdk/connectivity/src/ip_adapter/windows/caipnwmonitor.c index c0cf28a..5f40f13 100644 --- a/resource/csdk/connectivity/src/ip_adapter/windows/caipnwmonitor.c +++ b/resource/csdk/connectivity/src/ip_adapter/windows/caipnwmonitor.c @@ -150,8 +150,8 @@ static void CAIPDestroyNetworkMonitorList() */ static bool CACmpNetworkList(uint32_t ifIndex, int family, const char *addr, u_arraylist_t *iflist) { - uint32_t list_length = u_arraylist_length(iflist); - for (uint32_t list_index = 0; list_index < list_length; list_index++) + size_t list_length = u_arraylist_length(iflist); + for (size_t list_index = 0; list_index < list_length; list_index++) { CAInterface_t *currItem = (CAInterface_t *) u_arraylist_get(iflist, list_index); if ((currItem->index == ifIndex) && (currItem->family == family) && @@ -180,15 +180,15 @@ static void CALLBACK IpAddressChangeCallback(void *context, // Fetch new network address info. u_arraylist_t *newList = GetInterfaceInformation(0); - uint32_t newLen = u_arraylist_length(newList); + size_t newLen = u_arraylist_length(newList); u_arraylist_t *oldList = g_CAIPNetworkMonitorAddressList; - uint32_t oldLen = u_arraylist_length(oldList); + size_t oldLen = u_arraylist_length(oldList); if (caglobals.ip.addressChangeEvent) { // Check whether any addresses went away. - for (uint32_t i = 0; i < oldLen; i++) + for (size_t i = 0; i < oldLen; i++) { CAInterface_t *ifitem = (CAInterface_t *)u_arraylist_get(oldList, i); if (!CACmpNetworkList(ifitem->index, ifitem->family, ifitem->addr, newList)) @@ -199,7 +199,7 @@ static void CALLBACK IpAddressChangeCallback(void *context, } // Check whether any new addresses are available. - for (uint32_t i = 0; i < newLen; i++) + for (size_t i = 0; i < newLen; i++) { CAInterface_t *ifitem = (CAInterface_t *)u_arraylist_get(newList, i); if (!CACmpNetworkList(ifitem->index, ifitem->family, ifitem->addr, oldList)) @@ -275,7 +275,7 @@ DWORD WINAPI IpNetworkMonitorWorker(PVOID context) return err; } - SOCKET nwmSocket = WSASocket( + SOCKET nwmSocket = WSASocketW( AF_INET6, SOCK_DGRAM, 0, // Default proto. @@ -898,8 +898,8 @@ u_arraylist_t *CAIPGetInterfaceInformation(int desiredIndex) // Avoid extra kernel calls by just duplicating what's in our cache. oc_mutex_lock(g_CAIPNetworkMonitorMutex); - uint32_t list_length = u_arraylist_length(g_CAIPNetworkMonitorAddressList); - for (uint32_t list_index = 0; list_index < list_length; list_index++) + size_t list_length = u_arraylist_length(g_CAIPNetworkMonitorAddressList); + for (size_t list_index = 0; list_index < list_length; list_index++) { CAInterface_t *currItem = (CAInterface_t *)u_arraylist_get(g_CAIPNetworkMonitorAddressList, list_index); diff --git a/resource/csdk/connectivity/src/tcp_adapter/arduino/catcpserver_eth.cpp b/resource/csdk/connectivity/src/tcp_adapter/arduino/catcpserver_eth.cpp index 6e6404e..a601b60 100644 --- a/resource/csdk/connectivity/src/tcp_adapter/arduino/catcpserver_eth.cpp +++ b/resource/csdk/connectivity/src/tcp_adapter/arduino/catcpserver_eth.cpp @@ -274,7 +274,7 @@ void CATCPReadDataInternal() return; } -CAResult_t CAGetTCPInterfaceInformation(CAEndpoint_t **info, uint32_t *size) +CAResult_t CAGetTCPInterfaceInformation(CAEndpoint_t **info, size_t *size) { OIC_LOG(DEBUG, TAG, "IN"); @@ -297,7 +297,7 @@ static ssize_t sendData(const CAEndpoint_t *endpoint, return -1; } - if (dlen > 65535) // Max value for uint16_t + if (dlen > UINT16_MAX) { // This will never happen as max buffer size we are dealing with is COAP_MAX_PDU_SIZE OIC_LOG(ERROR, TAG, "Size exceeded"); diff --git a/resource/csdk/connectivity/src/tcp_adapter/catcpadapter.c b/resource/csdk/connectivity/src/tcp_adapter/catcpadapter.c index 6bdc2b0..fc78862 100755 --- a/resource/csdk/connectivity/src/tcp_adapter/catcpadapter.c +++ b/resource/csdk/connectivity/src/tcp_adapter/catcpadapter.c @@ -95,7 +95,7 @@ static CAErrorHandleCallback g_errorCallback = NULL; static CAKeepAliveConnectionCallback g_connKeepAliveCallback = NULL; static void CATCPPacketReceivedCB(const CASecureEndpoint_t *sep, - const void *data, uint32_t dataLength); + const void *data, size_t dataLength); static void CATCPErrorHandler(const CAEndpoint_t *endpoint, const void *data, size_t dataLength, CAResult_t result); @@ -157,7 +157,7 @@ void CATCPConnectionStateCB(const char *ipAddress, CANetworkStatus_t status) } void CATCPPacketReceivedCB(const CASecureEndpoint_t *sep, const void *data, - uint32_t dataLength) + size_t dataLength) { VERIFY_NON_NULL_VOID(sep, TAG, "sep is NULL"); VERIFY_NON_NULL_VOID(data, TAG, "data is NULL"); @@ -453,18 +453,15 @@ CAResult_t CAStartTCPDiscoveryServer() return CA_STATUS_OK; } -static size_t CAQueueTCPData(bool isMulticast, const CAEndpoint_t *endpoint, - const void *data, size_t dataLength) +static int32_t CAQueueTCPData(bool isMulticast, const CAEndpoint_t *endpoint, + const void *data, uint32_t dataLength) { VERIFY_NON_NULL_RET(endpoint, TAG, "endpoint", -1); VERIFY_NON_NULL_RET(data, TAG, "data", -1); - - if (0 == dataLength) - { - OIC_LOG(ERROR, TAG, "Invalid Data Length"); - return -1; - } - + VERIFY_TRUE_RET((dataLength <= INT_MAX) && (dataLength > 0), + TAG, + "Invalid Data Length", + -1); VERIFY_NON_NULL_RET(g_sendQueueHandle, TAG, "sendQueueHandle", -1); // Create TCPData to add to queue @@ -477,7 +474,7 @@ static size_t CAQueueTCPData(bool isMulticast, const CAEndpoint_t *endpoint, // Add message to send queue CAQueueingThreadAddData(g_sendQueueHandle, tcpData, sizeof(CATCPData)); - return dataLength; + return (int32_t)dataLength; } int32_t CASendTCPUnicastData(const CAEndpoint_t *endpoint, @@ -486,10 +483,16 @@ int32_t CASendTCPUnicastData(const CAEndpoint_t *endpoint, { OIC_LOG(DEBUG, TAG, "IN"); (void)dataType; + if ((0 == dataLength) || (dataLength > INT32_MAX)) + { + OIC_LOG(ERROR, TAG, "Invalid Data Length"); + return -1; + } + #ifndef SINGLE_THREAD return CAQueueTCPData(false, endpoint, data, dataLength); #else - return CATCPSendData(endpoint, data, dataLength); + return (int32_t)CATCPSendData(endpoint, data, dataLength); #endif } diff --git a/resource/csdk/connectivity/src/tcp_adapter/catcpserver.c b/resource/csdk/connectivity/src/tcp_adapter/catcpserver.c index 9b92cac..1da4e19 100644 --- a/resource/csdk/connectivity/src/tcp_adapter/catcpserver.c +++ b/resource/csdk/connectivity/src/tcp_adapter/catcpserver.c @@ -137,8 +137,13 @@ static CAResult_t CATCPCreateSocket(int family, CATCPSessionInfo_t *svritem); #define CHECKFD(FD) #else #define CHECKFD(FD) \ +do \ +{ \ if (FD > caglobals.tcp.maxfd) \ - caglobals.tcp.maxfd = FD; + { \ + caglobals.tcp.maxfd = FD; \ + } \ +} while (0) #endif #define CLOSE_SOCKET(TYPE) \ @@ -406,7 +411,7 @@ static void CAFindReadyMessage() CASocketFd_t socketArray[EVENT_ARRAY_SIZE] = {0}; HANDLE eventArray[_countof(socketArray)]; int arraySize = 0; - + if (OC_INVALID_SOCKET != caglobals.tcp.ipv4.fd) { CAPushSocket(caglobals.tcp.ipv4.fd, socketArray, eventArray, &arraySize, _countof(socketArray)); @@ -420,7 +425,7 @@ static void CAFindReadyMessage() CAPushEvent(OC_INVALID_SOCKET, socketArray, caglobals.tcp.updateEvent, eventArray, &arraySize, _countof(socketArray)); } - + int svrlistBeginIndex = arraySize; while (!caglobals.tcp.terminate) @@ -765,7 +770,7 @@ static void CAReceiveMessage(CASocketFd_t fd) nbRead = tlsLength - svritem->tlsLen; } - len = recv(fd, svritem->tlsdata + svritem->tlsLen, nbRead, 0); + len = recv(fd, svritem->tlsdata + svritem->tlsLen, (int)nbRead, 0); if (len < 0) { OIC_LOG_V(ERROR, TAG, "recv failed %s", strerror(errno)); @@ -784,7 +789,7 @@ static void CAReceiveMessage(CASocketFd_t fd) if (tlsLength > 0 && tlsLength == svritem->tlsLen) { //when successfully read data - pass them to callback. - res = CAdecryptSsl(&svritem->sep, (uint8_t *)svritem->tlsdata, svritem->tlsLen); + res = CAdecryptSsl(&svritem->sep, (uint8_t *)svritem->tlsdata, (int)svritem->tlsLen); svritem->tlsLen = 0; OIC_LOG_V(DEBUG, TAG, "%s: CAdecryptSsl returned %d", __func__, res); } @@ -1198,7 +1203,9 @@ size_t CACheckPayloadLengthFromHeader(const void *data, size_t dlen) coap_transport_t transport = coap_get_tcp_header_type_from_initbyte( ((unsigned char *)data)[0] >> 4); - coap_pdu_t *pdu = coap_new_pdu2(transport, dlen); + coap_pdu_t *pdu = coap_pdu_init2(0, 0, + ntohs(COAP_INVALID_TID), + dlen, transport); if (!pdu) { OIC_LOG(ERROR, TAG, "outpdu is null"); @@ -1215,7 +1222,7 @@ size_t CACheckPayloadLengthFromHeader(const void *data, size_t dlen) size_t payloadLen = 0; size_t headerSize = coap_get_tcp_header_length_for_transport(transport); - OIC_LOG_V(DEBUG, TAG, "headerSize : %zu, pdu length : %d", + OIC_LOG_V(DEBUG, TAG, "headerSize : %" PRIuPTR ", pdu length : %d", headerSize, pdu->length); if (pdu->length > headerSize) { @@ -1230,7 +1237,7 @@ size_t CACheckPayloadLengthFromHeader(const void *data, size_t dlen) static ssize_t sendData(const CAEndpoint_t *endpoint, const void *data, size_t dlen, const char *fam) { - OIC_LOG_V(INFO, TAG, "The length of data that needs to be sent is %zu bytes", dlen); + OIC_LOG_V(INFO, TAG, "The length of data that needs to be sent is %" PRIuPTR " bytes", dlen); // #1. find a session info from list. CASocketFd_t sockFd = CAGetSocketFDFromEndpoint(endpoint); @@ -1249,7 +1256,8 @@ static ssize_t sendData(const CAEndpoint_t *endpoint, const void *data, ssize_t remainLen = dlen; do { - ssize_t len = send(sockFd, data, remainLen, 0); + int dataToSend = (remainLen > INT_MAX) ? INT_MAX : (int)remainLen; + ssize_t len = send(sockFd, data, dataToSend, 0); if (-1 == len) { if (EWOULDBLOCK != errno) @@ -1268,7 +1276,7 @@ static ssize_t sendData(const CAEndpoint_t *endpoint, const void *data, #ifndef TB_LOG (void)fam; #endif - OIC_LOG_V(INFO, TAG, "unicast %stcp sendTo is successful: %zu bytes", fam, dlen); + OIC_LOG_V(INFO, TAG, "unicast %stcp sendTo is successful: %" PRIuPTR " bytes", fam, dlen); CALogSendStateInfo(endpoint->adapter, endpoint->addr, endpoint->port, dlen, true, NULL); return dlen; @@ -1293,7 +1301,7 @@ ssize_t CATCPSendData(CAEndpoint_t *endpoint, const void *data, size_t datalen) return -1; } -CAResult_t CAGetTCPInterfaceInformation(CAEndpoint_t **info, uint32_t *size) +CAResult_t CAGetTCPInterfaceInformation(CAEndpoint_t **info, size_t *size) { VERIFY_NON_NULL(info, TAG, "info is NULL"); VERIFY_NON_NULL(size, TAG, "size is NULL"); @@ -1305,7 +1313,7 @@ CAResult_t CAGetTCPInterfaceInformation(CAEndpoint_t **info, uint32_t *size) return CA_STATUS_FAILED; } - uint32_t len = u_arraylist_length(iflist); + size_t len = u_arraylist_length(iflist); CAEndpoint_t *ep = (CAEndpoint_t *)OICCalloc(len, sizeof (CAEndpoint_t)); if (!ep) @@ -1315,7 +1323,7 @@ CAResult_t CAGetTCPInterfaceInformation(CAEndpoint_t **info, uint32_t *size) return CA_MEMORY_ALLOC_FAILED; } - for (uint32_t i = 0, j = 0; i < len; i++) + for (size_t i = 0, j = 0; i < len; i++) { CAInterface_t *ifitem = (CAInterface_t *)u_arraylist_get(iflist, i); if (!ifitem) @@ -1562,9 +1570,9 @@ size_t CAGetTotalLengthFromHeader(const unsigned char *recvBuffer) transport); size_t headerLen = coap_get_tcp_header_length((unsigned char *)recvBuffer); - OIC_LOG_V(DEBUG, TAG, "option/paylaod length [%zu]", optPaylaodLen); - OIC_LOG_V(DEBUG, TAG, "header length [%zu]", headerLen); - OIC_LOG_V(DEBUG, TAG, "total data length [%zu]", headerLen + optPaylaodLen); + OIC_LOG_V(DEBUG, TAG, "option/paylaod length [%" PRIuPTR "]", optPaylaodLen); + OIC_LOG_V(DEBUG, TAG, "header length [%" PRIuPTR "]", headerLen); + OIC_LOG_V(DEBUG, TAG, "total data length [%" PRIuPTR "]", headerLen + optPaylaodLen); OIC_LOG(DEBUG, TAG, "OUT - CAGetTotalLengthFromHeader"); return headerLen + optPaylaodLen; diff --git a/resource/csdk/stack/src/ocpayload.c b/resource/csdk/stack/src/ocpayload.c index ce389aa..2c8648e 100644 --- a/resource/csdk/stack/src/ocpayload.c +++ b/resource/csdk/stack/src/ocpayload.c @@ -582,10 +582,8 @@ bool OCRepPayloadGetPropDouble(const OCRepPayload* payload, const char* name, do #ifdef _MSC_VER #pragma warning( suppress : 4244 ) *value = val->i; - #else *value = val->i; - #endif return true; } @@ -1155,10 +1153,8 @@ bool OCRepPayloadGetDoubleArray(const OCRepPayload* payload, const char* name, #ifdef _MSC_VER #pragma warning( suppress : 4244 ) (*array)[n] = val->arr.iArray[n]; - #else (*array)[n] = val->arr.iArray[n]; - #endif } } -- 2.7.4