removed defects detected by static analysis tool for linux
authorhyuna0213.jo <hyuna0213.jo@samsung.com>
Thu, 21 Jul 2016 04:26:01 +0000 (13:26 +0900)
committerJon A. Cruz <jon@joncruz.org>
Thu, 21 Jul 2016 19:48:36 +0000 (19:48 +0000)
- initialize some variables
- adjusted code style
- modified unreached code

Change-Id: I88a5a3d097c7d7c755c06a7b33508050bcb35591
Signed-off-by: hyuna0213.jo <hyuna0213.jo@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/8555
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Jon A. Cruz <jon@joncruz.org>
resource/csdk/connectivity/common/src/camutex_pthreads.c
resource/csdk/connectivity/src/adapter_util/caadapterutils.c
resource/csdk/connectivity/src/ip_adapter/caipserver.c
resource/csdk/connectivity/src/ip_adapter/linux/caipnwmonitor.c
resource/csdk/connectivity/src/tcp_adapter/catcpserver.c
resource/csdk/connectivity/test/ca_api_unittest.cpp
resource/csdk/connectivity/test/cablocktransfertest.cpp

index ef344fdf18798ba9a5846447f855f5af39425278..db790ec7ee9a5fc20d9243ebc8296238317ca76f 100644 (file)
@@ -425,8 +425,8 @@ CAWaitResult_t ca_cond_wait_for(ca_cond cond, ca_mutex mutex, uint64_t microseco
             retVal = CA_WAIT_SUCCESS;
         }
 #else
-        int ret;
-        struct timespec abstime;
+        int ret = 0;
+        struct timespec abstime = { .tv_sec = 0 };
 
 #ifdef __ANDROID__
         if (camutex_cond_timedwait_relative)
index 9ddc7e8aa0cd0d51904afea1200cf5df0e6becb1..888885bee4e72ae248c03277df368a913c16369d 100644 (file)
@@ -176,7 +176,7 @@ void CAConvertNameToAddr(const char *host, uint16_t port, struct sockaddr_storag
     VERIFY_NON_NULL_VOID(host, CA_ADAPTER_UTILS_TAG, "host is null");
     VERIFY_NON_NULL_VOID(sockaddr, CA_ADAPTER_UTILS_TAG, "sockaddr is null");
 
-    struct addrinfo *addrs;
+    struct addrinfo *addrs = NULL;
     struct addrinfo hints = { .ai_family = AF_UNSPEC,
                               .ai_socktype = SOCK_DGRAM,
                               .ai_flags = AI_NUMERICHOST };
index 360d449a1d1fe02362b82c2bf59165cb5f9b8c7a..8108328fd476d9ee7bd83b6f50291824063e60df 100644 (file)
@@ -485,9 +485,11 @@ static CAResult_t CAReceiveMessage(CASocketFd_t fd, CATransportFlags_t flags)
 {
     char recvBuffer[COAP_MAX_PDU_SIZE] = {0};
 
-    size_t len;
-    int level, type, namelen;
-    struct sockaddr_storage srcAddr;
+    size_t len = 0;
+    int level = 0;
+    int type = 0;
+    int namelen = 0;
+    struct sockaddr_storage srcAddr = { .ss_family = 0 };
     unsigned char *pktinfo = NULL;
 #if !defined(WSA_CMSG_DATA)
     struct cmsghdr *cmp = NULL;
@@ -667,7 +669,7 @@ static CASocketFd_t CACreateSocket(int family, uint16_t *port, bool isMulticast)
     }
 #endif
     struct sockaddr_storage sa = { .ss_family = family };
-    socklen_t socklen;
+    socklen_t socklen = 0;
 
     if (family == AF_INET6)
     {
@@ -1207,10 +1209,10 @@ static void sendData(int fd, const CAEndpoint_t *endpoint,
     (void)cast;  // eliminates release warning
     (void)fam;
 
-    struct sockaddr_storage sock;
+    struct sockaddr_storage sock = { .ss_family = 0 };
     CAConvertNameToAddr(endpoint->addr, endpoint->port, &sock);
 
-    socklen_t socklen;
+    socklen_t socklen = 0;
     if (sock.ss_family == AF_INET6)
     {
         /** @todo figure out correct usage for ifindex, and sin6_scope_id */
index cf1a771989ff356baef7c49aff27861384bad32c..40a05524cb2b052fc794100598688c924044cf5a 100644 (file)
@@ -218,11 +218,15 @@ CAInterface_t *CAFindInterfaceChange()
 {
     CAInterface_t *foundNewInterface = NULL;
 #ifdef __linux__
-    char buf[4096];
-    struct nlmsghdr *nh;
-    struct sockaddr_nl sa;
-    struct iovec iov = { buf, sizeof (buf) };
-    struct msghdr msg = { (void *)&sa, sizeof (sa), &iov, 1, NULL, 0, 0 };
+    char buf[4096] = { 0 };
+    struct nlmsghdr *nh = NULL;
+    struct sockaddr_nl sa = { .nl_family = 0 };
+    struct iovec iov = { .iov_base = buf,
+                         .iov_len = sizeof (buf) };
+    struct msghdr msg = { .msg_name = (void *)&sa,
+                          .msg_namelen = sizeof (sa),
+                          .msg_iov = &iov,
+                          .msg_iovlen = 1 };
 
     size_t len = recvmsg(caglobals.ip.netlinkFd, &msg, 0);
 
index 2300a4ddfe6d34e312d7c5bcea8ed1284f86ab23..737c41dc0381c8f9cad5a03ff34067c1f8d63fc3 100644 (file)
  */
 #define TAG "OIC_CA_TCP_SERVER"
 
-/**
- * Server port number for local test.
- */
-#define SERVER_PORT 8000
-
 /**
  * Maximum CoAP over TCP header length
  * to know the total data length.
@@ -481,7 +476,7 @@ static int CATCPCreateSocket(int family, CATCPSessionInfo_t *svritem)
     }
 
     // #3. set socket length.
-    socklen_t socklen;
+    socklen_t socklen = 0;
     if (sa.ss_family == AF_INET6)
     {
         struct sockaddr_in6 *sock6 = (struct sockaddr_in6 *)&sa;
@@ -519,7 +514,7 @@ static int CACreateAcceptSocket(int family, CASocket_t *sock)
         return sock->fd;
     }
 
-    socklen_t socklen;
+    socklen_t socklen = 0;
     struct sockaddr_storage server = { .ss_family = family };
 
     int fd = socket(family, SOCK_STREAM, IPPROTO_TCP);
index 6a947006c267053569c0962a8aa1a28683178648..eccca1188e4fb27dd503b75ae06f790084c7b923 100644 (file)
@@ -29,7 +29,8 @@
 
 class CATests : public testing::Test {
     protected:
-    virtual void SetUp() {
+    virtual void SetUp()
+    {
         CAInitialize();
     }
 
index 77cb32f93db54f071ced5318125ef166eec1d825..5efc4567d1d0ee8b623d70eccf4185c6104dee76 100644 (file)
@@ -213,14 +213,18 @@ TEST_F(CABlockTransferTests, CAGetPayloadFromBlockDataListTest)
     CABlockData_t *currData = CACreateNewBlockData(cadata);
     EXPECT_TRUE(currData != NULL);
 
-    size_t fullPayload = 0;
-    CAPayload_t payload = CAGetPayloadFromBlockDataList(currData->blockDataId,
-                                                        &fullPayload);
+    if (currData)
+    {
+        size_t fullPayload = 0;
+        CAPayload_t payload = CAGetPayloadFromBlockDataList(currData->blockDataId,
+                                                            &fullPayload);
 
-    size_t payloadLen = (payload != NULL) ? strlen((const char*) payload) : 0;
-    EXPECT_TRUE(fullPayload == payloadLen);
+        size_t payloadLen = (payload != NULL) ? strlen((const char*) payload) : 0;
+        EXPECT_TRUE(fullPayload == payloadLen);
+
+        CARemoveBlockDataFromList(currData->blockDataId);
+    }
 
-    CARemoveBlockDataFromList(currData->blockDataId);
     CADestroyDataSet(cadata);
     coap_delete_list(options);
     coap_delete_pdu(pdu);
@@ -306,12 +310,15 @@ TEST_F(CABlockTransferTests, CAAddBlockOption1InRequest)
     CABlockData_t *currData = CACreateNewBlockData(cadata);
     EXPECT_TRUE(currData != NULL);
 
-    EXPECT_EQ(CA_STATUS_OK, CAUpdateBlockOptionType(currData->blockDataId,
-                                                    COAP_OPTION_BLOCK1));
+    if (currData)
+    {
+        EXPECT_EQ(CA_STATUS_OK, CAUpdateBlockOptionType(currData->blockDataId,
+                                                        COAP_OPTION_BLOCK1));
 
-    EXPECT_EQ(CA_STATUS_OK, CAAddBlockOption1(&pdu, &requestData,
-                                              requestData.payloadSize,
-                                              currData->blockDataId, &options));
+        EXPECT_EQ(CA_STATUS_OK, CAAddBlockOption1(&pdu, &requestData,
+                                                  requestData.payloadSize,
+                                                  currData->blockDataId, &options));
+    }
 
     CADestroyDataSet(cadata);
     coap_delete_list(options);
@@ -359,12 +366,15 @@ TEST_F(CABlockTransferTests, CAAddBlockOption1InResponse)
     CABlockData_t *currData = CACreateNewBlockData(cadata);
     EXPECT_TRUE(currData != NULL);
 
-    EXPECT_EQ(CA_STATUS_OK, CAUpdateBlockOptionType(currData->blockDataId,
-                                                    COAP_OPTION_BLOCK1));
+    if (currData)
+    {
+        EXPECT_EQ(CA_STATUS_OK, CAUpdateBlockOptionType(currData->blockDataId,
+                                                        COAP_OPTION_BLOCK1));
 
-    EXPECT_EQ(CA_STATUS_OK, CAAddBlockOption1(&pdu, &responseData,
-                                              responseData.payloadSize,
-                                              currData->blockDataId, &options));
+        EXPECT_EQ(CA_STATUS_OK, CAAddBlockOption1(&pdu, &responseData,
+                                                  responseData.payloadSize,
+                                                  currData->blockDataId, &options));
+    }
 
     CADestroyDataSet(cadata);
     coap_delete_list(options);
@@ -412,12 +422,15 @@ TEST_F(CABlockTransferTests, CAAddBlockOption2InResponse)
     CABlockData_t *currData = CACreateNewBlockData(cadata);
     EXPECT_TRUE(currData != NULL);
 
-    EXPECT_EQ(CA_STATUS_OK, CAUpdateBlockOptionType(currData->blockDataId,
-                                                    COAP_OPTION_BLOCK2));
+    if (currData)
+    {
+        EXPECT_EQ(CA_STATUS_OK, CAUpdateBlockOptionType(currData->blockDataId,
+                                                        COAP_OPTION_BLOCK2));
 
-    EXPECT_EQ(CA_STATUS_OK, CAAddBlockOption2(&pdu, &responseData,
-                                              responseData.payloadSize,
-                                              currData->blockDataId, &options));
+        EXPECT_EQ(CA_STATUS_OK, CAAddBlockOption2(&pdu, &responseData,
+                                                  responseData.payloadSize,
+                                                  currData->blockDataId, &options));
+    }
 
     CADestroyDataSet(cadata);
     coap_delete_list(options);
@@ -464,14 +477,16 @@ TEST_F(CABlockTransferTests, CAAddBlockOption2InRequest)
     CABlockData_t *currData = CACreateNewBlockData(cadata);
     EXPECT_TRUE(currData != NULL);
 
-    EXPECT_EQ(CA_STATUS_OK, CAUpdateBlockOptionType(currData->blockDataId,
-                                                    COAP_OPTION_BLOCK2));
+    if (currData)
+    {
+        EXPECT_EQ(CA_STATUS_OK, CAUpdateBlockOptionType(currData->blockDataId,
+                                                        COAP_OPTION_BLOCK2));
 
-    EXPECT_EQ(CA_STATUS_OK, CAAddBlockOption2(&pdu, &requestData,
-                                              requestData.payloadSize,
-                                              currData->blockDataId, &options));
+        EXPECT_EQ(CA_STATUS_OK, CAAddBlockOption2(&pdu, &requestData,
+                                                  requestData.payloadSize,
+                                                  currData->blockDataId, &options));
+    }
 
-    CARemoveBlockDataFromList(currData->blockDataId);
     CADestroyDataSet(cadata);
     coap_delete_list(options);
     coap_delete_pdu(pdu);