csdk: Fix compiler warnings in ocresource.c
authorGeorge Nash <george.nash@intel.com>
Thu, 9 Mar 2017 23:12:14 +0000 (15:12 -0800)
committerDan Mihai <Daniel.Mihai@microsoft.com>
Mon, 13 Mar 2017 17:55:25 +0000 (17:55 +0000)
-Wunused-parameter - fixed using the OC_UNUSED macro
-Wtype-limits - the statment `if (dimensions[0] >= 0)` is
always true because the `dimensions` param  is size_t
which is never negative. Since its always true the if
statment was removed.

Change-Id: I08c9e68e9c688cd9f31bee8d9368a4eec6c8cc01
Signed-off-by: George Nash <george.nash@intel.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/17815
Tested-by: jenkins-iotivity <jenkins@iotivity.org>
Reviewed-by: Mike Fenelon <mike.fenelon@microsoft.com>
Reviewed-by: Dan Mihai <Daniel.Mihai@microsoft.com>
resource/csdk/stack/src/ocresource.c

index 3b5db32..abc4994 100755 (executable)
@@ -984,6 +984,8 @@ exit:
 OCStackResult BuildIntrospectionPayloadResponse(const OCResource *resourcePtr,
     OCRepPayload** payload, OCDevAddr *devAddr)
 {
+    OC_UNUSED(resourcePtr);
+    OC_UNUSED(devAddr);
     OCRepPayload *tempPayload = NULL;
     OCStackResult ret;
     char *introspectionData = NULL;
@@ -1113,6 +1115,7 @@ void FreeProtocolLL(OCStringLL *protoLL)
 OCStackResult BuildIntrospectionResponseRepresentation(const OCResource *resourcePtr,
     OCRepPayload** payload, OCDevAddr *devAddr)
 {
+    OC_UNUSED(devAddr);
     size_t dimensions[3] = { 0, 0, 0 };
     OCRepPayload *tempPayload = NULL;
     OCRepPayload **urlInfoPayload = NULL;
@@ -1228,42 +1231,39 @@ OCStackResult BuildIntrospectionResponseRepresentation(const OCResource *resourc
     }
 #endif
     // Add a urlInfo object for each protocol supported
-    if (dimensions[0] >= 0)
+    urlInfoPayload = (OCRepPayload **)OICMalloc(dimensions[0] * sizeof(OCRepPayload));
+    if (urlInfoPayload)
     {
-        urlInfoPayload = (OCRepPayload **)OICMalloc(dimensions[0] * sizeof(OCRepPayload));
-        if (urlInfoPayload)
+        OCStringLL *proto = protoLL;
+        size_t i = 0;
+        while (proto)
         {
-            OCStringLL *proto = protoLL;
-            size_t i = 0;
-            while (proto)
+            urlInfoPayload[i] = BuildUrlInfoWithProtocol(proto->value);
+            if (!urlInfoPayload[i])
             {
-                urlInfoPayload[i] = BuildUrlInfoWithProtocol(proto->value);
-                if (!urlInfoPayload[i])
-                {
-                    OIC_LOG(ERROR, TAG, "Unable to build urlInfo object for protocol");
-                    ret = OC_STACK_ERROR;
-                    goto exit;
-                }
-                proto = proto->next;
-                i++;
-            }
-            if (!OCRepPayloadSetPropObjectArrayAsOwner(tempPayload,
-                                                       OC_RSRVD_INTROSPECTION_URL_INFO,
-                                                       urlInfoPayload,
-                                                       dimensions))
-            {
-                OIC_LOG(ERROR, TAG, "Unable to add urlInfo object to introspection payload ");
+                OIC_LOG(ERROR, TAG, "Unable to build urlInfo object for protocol");
                 ret = OC_STACK_ERROR;
                 goto exit;
             }
+            proto = proto->next;
+            i++;
         }
-        else
+        if (!OCRepPayloadSetPropObjectArrayAsOwner(tempPayload,
+                                                   OC_RSRVD_INTROSPECTION_URL_INFO,
+                                                   urlInfoPayload,
+                                                   dimensions))
         {
-            OIC_LOG(ERROR, TAG, "Unable to allocate memory for urlInfo ");
-            ret = OC_STACK_NO_MEMORY;
+            OIC_LOG(ERROR, TAG, "Unable to add urlInfo object to introspection payload ");
+            ret = OC_STACK_ERROR;
             goto exit;
         }
     }
+    else
+    {
+        OIC_LOG(ERROR, TAG, "Unable to allocate memory for urlInfo ");
+        ret = OC_STACK_NO_MEMORY;
+        goto exit;
+    }
 
     if (!*payload)
     {