Fix defects detected by static code analyzer
authorJaewook Jung <jw0213.jung@samsung.com>
Fri, 19 May 2017 02:02:29 +0000 (11:02 +0900)
committerAshok Babu Channa <ashok.channa@samsung.com>
Mon, 22 May 2017 06:39:32 +0000 (06:39 +0000)
 - fixed memory leak
 - removed unreachable codes
 - add a null checking before refer a character pointer

Change-Id: Ie49c44f0d2e5211dec24a607382c202900b4f6a3
Signed-off-by: Jaewook Jung <jw0213.jung@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/20087
Tested-by: jenkins-iotivity <jenkins@iotivity.org>
Reviewed-by: Glen Youngjin Kim <glen.kim@samsung.com>
Reviewed-by: Uze Choi <uzchoi@samsung.com>
Reviewed-by: Ashok Babu Channa <ashok.channa@samsung.com>
resource/csdk/connectivity/src/bt_edr_adapter/caedradapter.c
resource/csdk/connectivity/src/caprotocolmessage.c
resource/csdk/stack/src/ocstack.c

index cdff8ba..1fade67 100644 (file)
@@ -512,12 +512,6 @@ void CAAdapterDataSendHandler(void *context)
     }
 
     const char *remoteAddress = message->remoteEndpoint->addr;
-    if(!remoteAddress)
-    {
-        OIC_LOG(ERROR, TAG, "EDR Send Message error");
-        //Error cannot be sent if remote address is NULL
-        return;
-    }
 
     CAResult_t result = CAEDRClientSendData(remoteAddress, message->data, message->dataLen);
     if(CA_STATUS_OK != result)
index ffe21e7..1a1890f 100755 (executable)
@@ -300,12 +300,6 @@ coap_pdu_t *CAGeneratePDUImpl(code_t code, const CAInfo_t *info,
             msgLength = msgLength + info->payloadSize + PAYLOAD_MARKER;
         }
 
-        if (msgLength > UINT_MAX)
-        {
-            OIC_LOG(ERROR, TAG, "Message length too large.");
-            return NULL;
-        }
-
         *transport = coap_get_tcp_header_type_from_size((unsigned int)msgLength);
         length = msgLength + coap_get_tcp_header_length_for_transport(*transport)
                 + info->tokenLength;
index 5b18351..4d04010 100644 (file)
@@ -3609,10 +3609,10 @@ OCStackResult OCDoRequest(OCDoHandle *handle,
         goto exit;
     }
 #endif
-    
+
 #if defined(__WITH_DTLS__) || defined(__WITH_TLS__)
     /* Check whether we should assert role certificates before making this request. */
-    if ((endpoint.flags & CA_SECURE) && 
+    if ((endpoint.flags & CA_SECURE) && (NULL != requestInfo.info.resourceUri) &&
         (strcmp(requestInfo.info.resourceUri, OIC_RSRC_ROLES_URI) != 0) &&
         (strcmp(requestInfo.info.resourceUri, OIC_RSRC_DOXM_URI) != 0))
     {
@@ -3620,18 +3620,19 @@ OCStackResult OCDoRequest(OCDoHandle *handle,
         CAResult_t caRes = CAGetSecureEndpointData(&endpoint, &sep);
         if (caRes != CA_STATUS_OK)
         {
-            /* 
-             * This is a secure request but we do not have a secure connection with 
-             * this peer, try to assert roles. There's no way to tell if the peer 
-             * uses certificates without asking, so just try to assert roles.  If 
+            /*
+             * This is a secure request but we do not have a secure connection with
+             * this peer, try to assert roles. There's no way to tell if the peer
+             * uses certificates without asking, so just try to assert roles.  If
              * it fails, that's OK, roles will get asserted "automatically" when PSK
              * credentials are used.
              */
-            OIC_LOG_V(DEBUG, TAG, "%s: going to try to assert roles before doing request to %s ", 
+            OIC_LOG_V(DEBUG, TAG, "%s: going to try to assert roles before doing request to %s ",
                       __func__, requestInfo.info.resourceUri);
             OCDevAddr da;
             CopyEndpointToDevAddr(&endpoint, &da);
-            OCStackResult assertResult = OCAssertRoles((void*)ASSERT_ROLES_CTX, &da, &assertRolesCB);
+            OCStackResult assertResult = OCAssertRoles((void*)ASSERT_ROLES_CTX, &da,
+                                                       &assertRolesCB);
             if (assertResult == OC_STACK_OK)
             {
                 OIC_LOG_V(DEBUG, TAG, "%s: Call to OCAssertRoles succeeded", __func__);
@@ -3644,12 +3645,12 @@ OCStackResult OCDoRequest(OCDoHandle *handle,
             {
                 OIC_LOG_V(DEBUG, TAG, "%s: Call to OCAssertRoles failed", __func__);
             }
-            
-            /* 
+
+            /*
              * We don't block waiting for OCAssertRoles to complete.  Because the roles assertion
              * request is queued before the actual request, it will happen first.  If it fails, we
              * log the error, but don't retry; the actually request made to OCDorequest may or may
-             * not fail (with permission denied), the caller can decide whether to retry. 
+             * not fail (with permission denied), the caller can decide whether to retry.
              */
         }