Fix static analysis issue in ocresource
authorJaehong Jo <jaehong.jo@samsung.com>
Wed, 30 Nov 2016 08:25:53 +0000 (17:25 +0900)
committerDan Mihai <Daniel.Mihai@microsoft.com>
Wed, 7 Dec 2016 16:19:59 +0000 (16:19 +0000)
- add initial value and null checking

Change-Id: I50731d23865c72d2c03cb3b149b19bf4236bf587
Signed-off-by: Jaehong Jo <jaehong.jo@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/14955
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Ziran Sun <ziran.sun@samsung.com>
Reviewed-by: Phil Coval <philippe.coval@osg.samsung.com>
Reviewed-by: Ashok Babu Channa <ashok.channa@samsung.com>
(cherry picked from commit 2bf1598fa14d918f3c254feaedd61716cba8d0f1)
Reviewed-on: https://gerrit.iotivity.org/gerrit/15101
Reviewed-by: Dan Mihai <Daniel.Mihai@microsoft.com>
resource/csdk/stack/src/ocresource.c

index 65ea233..3958298 100755 (executable)
@@ -1578,7 +1578,7 @@ OCStackResult OCGetPropertyValue(OCPayloadType type, const char *prop, void **va
 OCStackResult OCSetAttribute(OCResource* resource, const char* attribute, const void* value)
 {
     // See if the attribute already exists in the list.
-    OCAttribute *resAttrib;
+    OCAttribute *resAttrib = NULL;
     for (resAttrib = resource->rsrcAttributes; resAttrib; resAttrib = resAttrib->next)
     {
         if (0 == strcmp(attribute, resAttrib->attrName))
@@ -1628,7 +1628,7 @@ exit:
 
 OCStackResult OCSetPropertyValue(OCPayloadType type, const char *prop, const void *value)
 {
-    if (!prop)
+    if (!prop || !value)
     {
         return OC_STACK_INVALID_PARAM;
     }
@@ -1646,7 +1646,7 @@ OCStackResult OCSetPropertyValue(OCPayloadType type, const char *prop, const voi
         {
             OIC_LOG(ERROR, TAG, "Resource does not exist.");
         }
-        if (value)
+        else
         {
             res = OCSetAttribute(resource, prop, value);
         }