Fixing errors reported by Klocwork tool
authorSachin Agrawal <sachin.agrawal@intel.com>
Fri, 20 Feb 2015 14:20:56 +0000 (06:20 -0800)
committerPatrick Lankswert <patrick.lankswert@intel.com>
Mon, 23 Feb 2015 16:00:22 +0000 (16:00 +0000)
Error Report from Klocwork

1)FUNCRET.GEN: Non-void function does not return value :
 C and C++ : gen_sec_bin.cpp : Critical (1) : Analyze : Local

2)NPD.CHECK.MIGHT: Pointer 'fps' checked for NULL at line 123
 may be dereferenced at line 132. : C and C++ : gen_sec_bin.cpp :
 Critical (1) : Analyze : Local

3)NPD.FUNC.MIGHT: Pointer 'fps' returned from call to function 'fopen'
 at line 123 may be NULL and may be dereferenced at line 132. :
 C and C++ : gen_sec_bin.cpp : Critical (1) : Analyze : Local

4)UNINIT.STACK.ARRAY.MIGHT: 'payload' array elements might be used
 uninitialized in this function. : C and C++ : ocserverbasicops.cpp :
 Critical (1) : Analyze : Local

Change-Id: I970bc060191caf17b102b165bbe5656b079ad063
Signed-off-by: Sachin Agrawal <sachin.agrawal@intel.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/374
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Joseph Morrow <joseph.l.morrow@intel.com>
Reviewed-by: Patrick Lankswert <patrick.lankswert@intel.com>
resource/csdk/stack/samples/linux/secure/gen_sec_bin.cpp
resource/csdk/stack/samples/linux/secure/ocserverbasicops.cpp

index 89b8369..e0a4e02 100644 (file)
@@ -129,7 +129,7 @@ int main()
 
     if ((fpc = (FILE*) fopen("client_cred.bin", "wb")) != NULL)
     {
-        fwrite(oscd_c, SizeOfOCConfigData(oscd_c), 1, fps);
+        fwrite(oscd_c, SizeOfOCConfigData(oscd_c), 1, fpc);
         fclose(fpc);
     }
 
@@ -165,5 +165,6 @@ int main()
     printStruct("Server", (OCSecConfigData*)buf_s);
     printStruct("Client", (OCSecConfigData*)buf_c);
 
+    return 1;
 }
 
index acaa52b..4105740 100644 (file)
@@ -225,7 +225,7 @@ OCEntityHandlerCb (OCEntityHandlerFlag flag,
 
     OCEntityHandlerResult ehResult = OC_EH_ERROR;
     OCEntityHandlerResponse response;
-    char payload[MAX_RESPONSE_LENGTH];
+    char payload[MAX_RESPONSE_LENGTH] = {0};
 
     if (flag & OC_INIT_FLAG)
     {
@@ -256,6 +256,7 @@ OCEntityHandlerCb (OCEntityHandlerFlag flag,
             {
                 OC_LOG_V (INFO, TAG, "Received unsupported method %d from client",
                         entityHandlerRequest->method);
+                ehResult = OC_EH_ERROR;
             }
 
             if (ehResult == OC_EH_OK)