[IOT-2741] Static analysis warning fixes set-2. 85/22385/8
authorarya.k <arya.kumar@samsung.com>
Mon, 18 Sep 2017 04:37:35 +0000 (10:07 +0530)
committerAshok Babu Channa <ashok.channa@samsung.com>
Fri, 6 Oct 2017 11:22:22 +0000 (11:22 +0000)
1. Assign default values
2. Remove constants from decision making statements.
3. Add return by values.
4. Remove duplicate lines.
5. Indentations.

Change-Id: I8b3ba896bf72600bc9ee4fcbdc844506bdabf38f
Signed-off-by: arya.k <arya.kumar@samsung.com>
resource/csdk/connectivity/inc/caprotocolmessage.h
resource/csdk/connectivity/src/camessagehandler.c
resource/csdk/connectivity/src/caprotocolmessage.c
resource/csdk/stack/src/ocobserve.c
resource/csdk/stack/src/ocpayloadconvert.c
resource/csdk/stack/src/ocpayloadparse.c
resource/src/InProcClientWrapper.cpp

index a119027..3756e68 100644 (file)
@@ -50,7 +50,9 @@ typedef uint32_t code_t;
 #define HAVE_TIME_H 1
 #endif
 
+#ifdef WITH_TCP
 static const uint8_t PAYLOAD_MARKER = 1;
+#endif
 
 /**
  * generates pdu structure from the given information.
index 3750801..8829f13 100644 (file)
@@ -1165,7 +1165,7 @@ CAResult_t CAInitializeMessageHandler(CATransportAdapter_t transportType)
 void CATerminateMessageHandler()
 {
 #ifndef SINGLE_THREAD
-    CATransportAdapter_t connType;
+    CATransportAdapter_t connType = CA_DEFAULT_ADAPTER;
     u_arraylist_t *list = CAGetSelectedNetworkList();
     size_t length = u_arraylist_length(list);
 
index 3ac0015..8d9abb9 100644 (file)
@@ -750,17 +750,13 @@ CAResult_t CAGetInfoFromPDU(const coap_pdu_t *pdu, const CAEndpoint_t *endpoint,
     VERIFY_NON_NULL(outCode, TAG, "outCode");
     VERIFY_NON_NULL(outInfo, TAG, "outInfo");
 
-    coap_transport_t transport;
+    coap_transport_t transport = COAP_UDP;
 #ifdef WITH_TCP
     if (CAIsSupportedCoAPOverTCP(endpoint->adapter))
     {
         transport = coap_get_tcp_header_type_from_initbyte(((unsigned char *)pdu->transport_hdr)[0] >> 4);
     }
-    else
 #endif
-    {
-        transport = COAP_UDP;
-    }
 
     coap_opt_iterator_t opt_iter;
     coap_option_iterator_init2((coap_pdu_t *) pdu, &opt_iter, COAP_OPT_ALL, transport);
index ac6e9e4..2949e00 100644 (file)
@@ -673,14 +673,14 @@ HandleVirtualObserveRequest(OCServerRequest *request)
         // The request is to send an observe payload, not register/deregister an observer
         goto exit;
     }
-    OCVirtualResources virtualUriInRequest;
+    OCVirtualResources virtualUriInRequest = OC_UNKNOWN_URI;
     virtualUriInRequest = GetTypeOfVirtualURI(request->resourceUrl);
     if (virtualUriInRequest != OC_WELL_KNOWN_URI)
     {
         // OC_WELL_KNOWN_URI is currently the only virtual resource that may be observed
         goto exit;
     }
-    OCResource *resourcePtr;
+    OCResource *resourcePtr = NULL;
     resourcePtr = FindResourceByUri(OC_RSRVD_WELL_KNOWN_URI);
     if (NULL == resourcePtr)
     {
index fe50295..514f702 100644 (file)
@@ -827,7 +827,7 @@ static int64_t OCConvertRepMap(CborEncoder *map, const OCRepPayload *payload)
     arrayLength = 0;
     for (value = payload->values; value; value = value->next)
     {
-        char *endp;
+        char *endp = NULL;
         long i = strtol(value->name, &endp, 0);
         if (*endp != '\0' || i < 0 || arrayLength != (size_t)i)
         {
index 07cd381..03c798b 100644 (file)
@@ -332,7 +332,7 @@ static OCStackResult OCParseDiscoveryPayloadCbor(OCPayload **outPayload,
                 VERIFY_CBOR_SUCCESS_OR_OUT_OF_MEMORY(TAG, err, "to find port tag");
                 if (cbor_value_is_integer(&curVal))
                 {
-                    int port;
+                    int port = 0;
 
                     err = cbor_value_get_int(&curVal, &port);
                     VERIFY_CBOR_SUCCESS_OR_OUT_OF_MEMORY(TAG, err, "to find port value");
@@ -344,7 +344,7 @@ static OCStackResult OCParseDiscoveryPayloadCbor(OCPayload **outPayload,
                 err = cbor_value_map_find_value(&policyMap, OC_RSRVD_TCP_PORT, &curVal);
                 if (cbor_value_is_integer(&curVal))
                 {
-                    int tcpPort;
+                    int tcpPort = 0;
 
                     err = cbor_value_get_int(&curVal, &tcpPort);
                     VERIFY_CBOR_SUCCESS_OR_OUT_OF_MEMORY(TAG, err, "to find tcp port value");
@@ -356,7 +356,7 @@ static OCStackResult OCParseDiscoveryPayloadCbor(OCPayload **outPayload,
                 err = cbor_value_map_find_value(&policyMap, OC_RSRVD_TLS_PORT, &curVal);
                 if (cbor_value_is_integer(&curVal))
                 {
-                    int tlsPort;
+                    int tlsPort = 0;
 
                     err = cbor_value_get_int(&curVal, &tlsPort);
                     VERIFY_CBOR_SUCCESS_OR_OUT_OF_MEMORY(TAG, err, "to find tcp tls port value");
@@ -419,7 +419,7 @@ static CborError ParseResources(OCDiscoveryPayload **outPayload, CborValue *reso
     // Iterate through the array processing each resource which shows up as a map.
     while (cbor_value_is_map(resourceMap))
     {
-        int bitmap;
+        int bitmap = 0;
 
         resource = (OCResourcePayload *)OICCalloc(1, sizeof(OCResourcePayload));
         VERIFY_PARAM_NON_NULL(TAG, resource, "Failed allocating resource payload");
@@ -552,15 +552,16 @@ static CborError ParseResources(OCDiscoveryPayload **outPayload, CborValue *reso
         err = cbor_value_advance(resourceMap);
         VERIFY_CBOR_SUCCESS_OR_OUT_OF_MEMORY(TAG, err, "to advance resource map");
 
+        char* anchorPrefix =  "ocf://";
         // Parse di from anchor
-        if (!resource->anchor || strncmp(resource->anchor, "ocf://", 6))
+        if (!resource->anchor || strncmp(resource->anchor, anchorPrefix, strlen(anchorPrefix)))
         {
             OIC_LOG_V(ERROR, TAG, "Ignore unrecognized anchor %s", resource->anchor);
             OCDiscoveryResourceDestroy(resource);
         }
         else
         {
-            char *di = OICStrdup(resource->anchor + 6);
+            char *di = OICStrdup(resource->anchor + strlen(anchorPrefix));
             VERIFY_PARAM_NON_NULL(TAG, di, "Failed to duplicating di");
 
             char *slash = strchr(di, '/');
@@ -1228,7 +1229,8 @@ static OCStackResult OCParseRepPayload(OCPayload **outPayload, CborValue *root)
         ret = OC_STACK_MALFORMED_RESPONSE;
 
         // temporary fix to check for malformed cbor payload
-        if (!cbor_value_is_map(&rootMap) && !cbor_value_is_array(&rootMap)){
+        if (!cbor_value_is_map(&rootMap) && !cbor_value_is_array(&rootMap))
+        {
             goto exit;
         }
 
index e21e867..2b1da74 100644 (file)
@@ -1285,10 +1285,6 @@ namespace OC
         {
             method = OC_REST_OBSERVE;
         }
-        else if (observeType == ObserveType::ObserveAll)
-        {
-            method = OC_REST_OBSERVE_ALL;
-        }
         else
         {
             method = OC_REST_OBSERVE_ALL;