Revert "[IOT - 2386] Fix for NULL reference..."
authorDan Mihai <Daniel.Mihai@microsoft.com>
Thu, 22 Jun 2017 19:32:59 +0000 (12:32 -0700)
committerDan Mihai <Daniel.Mihai@microsoft.com>
Tue, 27 Jun 2017 18:19:38 +0000 (18:19 +0000)
This reverts commit 2819a9def15e8b401ee21ab1f941fa2af8a3f41e.

LL_FOREACH_SAFE already checks for NULL list entry, so there is no
need to check a second time inside the loop.

Change-Id: Ia7a33ce6a3c6bb88cd529831af07010729a2badb
Signed-off-by: Dan Mihai <Daniel.Mihai@microsoft.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/20963
Reviewed-by: Phil Coval <philippe.coval@osg.samsung.com>
Tested-by: jenkins-iotivity <jenkins@iotivity.org>
plugins/src/pluginlist.c

index 2d89d73..2b5b661 100644 (file)
@@ -69,13 +69,10 @@ OCStackResult DeletePluginList()
     PIPluginBase * tmp = NULL;
     LL_FOREACH_SAFE(pluginList, out, tmp)
     {
-        if(out)
+        result = DeletePlugin(out);
+        if (result != OC_STACK_OK)
         {
-            result = DeletePlugin(out);
-            if (result != OC_STACK_OK)
-            {
-                break;
-            }            
+            break;
         }
     }
     if (result == OC_STACK_OK)
@@ -96,7 +93,7 @@ OCStackResult GetResourceFromHandle(PIPluginBase * plugin, PIResource ** piResou
     PIResourceBase * tmp = NULL;
     LL_FOREACH_SAFE(plugin->resourceList, out, tmp)
     {
-        if (out && out->piResource.resourceHandle == resourceHandle)
+        if (out->piResource.resourceHandle == resourceHandle)
         {
             *piResource = (PIResource *) out;
             return OC_STACK_OK;
@@ -144,36 +141,33 @@ OCStackResult GetResourceFromZigBeeNodeId(PIPluginBase * plugin,
     size_t indexLength = 0;
     LL_FOREACH_SAFE(plugin->resourceList, out, tmp)
     {
-        if(out)
+        indexLength = strlen(((PIResource_Zigbee *)out)->nodeId);
+        if(ZigbeeStrEquals(nodeId,
+                           ((PIResource_Zigbee *)out)->nodeId,
+                           checkNodeIdLength,
+                           indexLength) == false)
         {
-            indexLength = strlen(((PIResource_Zigbee *)out)->nodeId);
-            if(ZigbeeStrEquals(nodeId,
-                               ((PIResource_Zigbee *)out)->nodeId,
-                               checkNodeIdLength,
-                               indexLength) == false)
-            {
-                continue;
-            }
-            indexLength = strlen(((PIResource_Zigbee *)out)->endpointId);
-            if(ZigbeeStrEquals(endpointId,
-                               ((PIResource_Zigbee *)out)->endpointId,
-                               checkEndpointIdLength,
-                               indexLength) == false)
-            {
-                continue;
-            }
-            indexLength = strlen(((PIResource_Zigbee *)out)->clusterId);
-            if(ZigbeeStrEquals(clusterId,
-                               ((PIResource_Zigbee *)out)->clusterId,
-                               checkClusterIdLength,
-                               indexLength) == false)
-            {
-                continue;
-            }
-            OIC_LOG_V(INFO, TAG, "Found a match! URI = %s", out->piResource.uri);
-            *piResource = (PIResource_Zigbee *) out;
-            return OC_STACK_OK;
+            continue;
+        }
+        indexLength = strlen(((PIResource_Zigbee *)out)->endpointId);
+        if(ZigbeeStrEquals(endpointId,
+                           ((PIResource_Zigbee *)out)->endpointId,
+                           checkEndpointIdLength,
+                           indexLength) == false)
+        {
+            continue;
+        }
+        indexLength = strlen(((PIResource_Zigbee *)out)->clusterId);
+        if(ZigbeeStrEquals(clusterId,
+                           ((PIResource_Zigbee *)out)->clusterId,
+                           checkClusterIdLength,
+                           indexLength) == false)
+        {
+            continue;
         }
+        OIC_LOG_V(INFO, TAG, "Found a match! URI = %s", out->piResource.uri);
+        *piResource = (PIResource_Zigbee *) out;
+        return OC_STACK_OK;
     }
     *piResource = NULL;
     return OC_STACK_NO_RESOURCE;
@@ -208,15 +202,12 @@ OCStackResult UpdateZigbeeResourceNodeId(PIPluginBase * plugin,
     size_t checkLength = strlen(eui);
     LL_FOREACH_SAFE(plugin->resourceList, out, tmp)
     {
-        if(out)
+        size_t indexLength = strlen(((PIResource_Zigbee *)out)->eui);
+        if(ZigbeeStrEquals(eui, ((PIResource_Zigbee *)out)->eui, checkLength, indexLength) != true)
         {
-            size_t indexLength = strlen(((PIResource_Zigbee *)out)->eui);
-            if(ZigbeeStrEquals(eui, ((PIResource_Zigbee *)out)->eui, checkLength, indexLength) != true)
-            {
-                continue;
-            }
-            OICStrcpy(((PIResource_Zigbee *)out)->nodeId, (strlen(nodeId)+1)*sizeof(char), nodeId);            
+            continue;
         }
+        OICStrcpy(((PIResource_Zigbee *)out)->nodeId, (strlen(nodeId)+1)*sizeof(char), nodeId);
     }
     return OC_STACK_OK;
 }
@@ -265,13 +256,10 @@ OCStackResult DeleteResourceList(PIPluginBase * plugin)
 
     LL_FOREACH_SAFE(plugin->resourceList, out, tmp)
     {
-        if(out)
+        result = DeleteResource(plugin, out);
+        if (result != OC_STACK_OK)
         {
-            result = DeleteResource(plugin, out);
-            if (result != OC_STACK_OK)
-            {
-                break;
-            }            
+            break;
         }
     }
     if (result == OC_STACK_OK)