Fix static analysis issue in ocresource
authorJaehong Jo <jaehong.jo@samsung.com>
Wed, 30 Nov 2016 08:25:53 +0000 (17:25 +0900)
committerAshok Babu Channa <ashok.channa@samsung.com>
Wed, 30 Nov 2016 13:01:25 +0000 (13:01 +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>
resource/csdk/stack/src/ocresource.c

index afeecc8..aad78ec 100755 (executable)
@@ -1477,7 +1477,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))
@@ -1527,7 +1527,7 @@ exit:
 
 OCStackResult OCSetPropertyValue(OCPayloadType type, const char *prop, const void *value)
 {
-    if (!prop)
+    if (!prop || !value)
     {
         return OC_STACK_INVALID_PARAM;
     }
@@ -1545,7 +1545,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);
         }