WARNING: eliminate warnings: [-Wsometimes-uninitialized]
authorGregg Reynolds <reynolds-gregg@norc.org>
Sat, 11 Jun 2016 13:08:55 +0000 (08:08 -0500)
committerHabib Virji <habib.virji@samsung.com>
Wed, 15 Jun 2016 15:23:10 +0000 (15:23 +0000)
The warning is caused by decls "TWEntry* entry = NULL;" coming
after tests that call "goto exit;" where "entry" is used.
the decl in front of the conditionals removes the warning.

Also added NULL test on "entry" to avoid unecessary calls
to TWDeleteEntry.

Change-Id: I0d7069e2497563a2c5378789c26acfdd3c48d89d
Signed-off-by: Gregg Reynolds <reynolds-gregg@norc.org>
Reviewed-on: https://gerrit.iotivity.org/gerrit/8599
Reviewed-by: George Nash <george.nash@intel.com>
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Habib Virji <habib.virji@samsung.com>
plugins/zigbee_wrapper/telegesis_wrapper/src/telegesis_wrapper.c

index 08728ef..888a1ff 100644 (file)
@@ -420,6 +420,8 @@ OCStackResult TWSetAttribute(char* extendedUniqueId, char* nodeId, char* endpoin
                 SEPARATOR_LENGTH + strlen(attributeType) +
                 SEPARATOR_LENGTH + strlen(newValue) + 1;
 
+    TWEntry* entry = NULL;
+
     char* cmdString = (char*)OICMalloc(size * sizeof(char));
     if (cmdString == NULL)
     {
@@ -440,7 +442,6 @@ OCStackResult TWSetAttribute(char* extendedUniqueId, char* nodeId, char* endpoin
     }
     OIC_LOG_V(INFO, TAG, "Write %s", cmdString);
 
-    TWEntry* entry = NULL;
     twRet = TWDequeueEntry(ctx->g_plugin, &entry, TW_WRITEATTR);
     if (twRet != TW_RESULT_OK)
     {
@@ -472,7 +473,10 @@ OCStackResult TWSetAttribute(char* extendedUniqueId, char* nodeId, char* endpoin
     ret = OC_STACK_OK;
 
 exit:
-    TWDeleteEntry(ctx->g_plugin, entry);
+    if (entry != NULL)
+    {
+        TWDeleteEntry(ctx->g_plugin, entry);
+    }
     OICFree(cmdString);
     OIC_LOG_V(INFO, TAG, "Leave TWSetAttribute() with ret=%d", ret);
     return ret;
@@ -504,6 +508,8 @@ OCStackResult TWGetAttribute(char* extendedUniqueId, char* nodeId, char* endpoin
                 SEPARATOR_LENGTH + strlen(clusterId) +
                 SEPARATOR_LENGTH + strlen(attributeId) + 1;
 
+    TWEntry* entry = NULL;
+
     char* cmdString = (char*)OICMalloc(size * sizeof(char));
     if (cmdString == NULL)
     {
@@ -532,7 +538,6 @@ OCStackResult TWGetAttribute(char* extendedUniqueId, char* nodeId, char* endpoin
     }
     OIC_LOG_V(INFO, TAG, "Write %s", cmdString);
 
-    TWEntry* entry = NULL;
     twRet = TWDequeueEntry(ctx->g_plugin, &entry, TW_RESPATTR);
     if (twRet != TW_RESULT_OK)
     {
@@ -573,7 +578,10 @@ OCStackResult TWGetAttribute(char* extendedUniqueId, char* nodeId, char* endpoin
     ret = OC_STACK_OK;
 
 exit:
-    TWDeleteEntry(ctx->g_plugin, entry);
+    if (entry != NULL)
+    {
+        TWDeleteEntry(ctx->g_plugin, entry);
+    }
     OICFree(cmdString);
     OIC_LOG_V(INFO, TAG, "Leave TWGetAttribute() with ret=%d", ret);
     return ret;
@@ -614,6 +622,8 @@ OCStackResult TWSwitchOnOff(char* nodeId, char* endpointId, char* newState,
                 SEPARATOR_LENGTH + strlen(newState) + 1;
     }
 
+    TWEntry* entry = NULL;
+
     char* cmdString = (char*)OICMalloc(size * sizeof(char));
     if (cmdString == NULL)
     {
@@ -646,7 +656,6 @@ OCStackResult TWSwitchOnOff(char* nodeId, char* endpointId, char* newState,
     }
     OIC_LOG_V(INFO, TAG, "Write %s", cmdString);
 
-    TWEntry* entry = NULL;
     twRet = TWDequeueEntry(ctx->g_plugin, &entry, TW_DFTREP);
     if (twRet != TW_RESULT_OK)
     {
@@ -672,7 +681,10 @@ OCStackResult TWSwitchOnOff(char* nodeId, char* endpointId, char* newState,
     ret = OC_STACK_OK;
 
 exit:
-    TWDeleteEntry(ctx->g_plugin, entry);
+    if (entry != NULL)
+    {
+        TWDeleteEntry(ctx->g_plugin, entry);
+    }
     OICFree(cmdString);
     OIC_LOG_V(INFO, TAG, "Leave TWSwitchOnOff() with ret=%d", ret);
     return ret;
@@ -704,6 +716,8 @@ OCStackResult TWMoveToLevel(char* nodeId, char* endpointId,
             SEPARATOR_LENGTH + strlen(level) +
             SEPARATOR_LENGTH + strlen(transTime) + 1;
 
+    TWEntry* entry = NULL;
+
     char* cmdString = (char*)OICMalloc(size * sizeof(char));
     if (cmdString == NULL)
     {
@@ -736,7 +750,6 @@ OCStackResult TWMoveToLevel(char* nodeId, char* endpointId,
 
     OIC_LOG_V(INFO, TAG, "Write %s", cmdString);
 
-    TWEntry* entry = NULL;
     twRet = TWDequeueEntry(ctx->g_plugin, &entry, TW_DFTREP);
     if (twRet != TW_RESULT_OK)
     {
@@ -762,7 +775,10 @@ OCStackResult TWMoveToLevel(char* nodeId, char* endpointId,
     ret = OC_STACK_OK;
 
 exit:
-    TWDeleteEntry(ctx->g_plugin, entry);
+    if (entry != NULL)
+    {
+        TWDeleteEntry(ctx->g_plugin, entry);
+    }
     OICFree(cmdString);
     OIC_LOG_V(INFO, TAG, "Leave TWMoveToLevel() with ret=%d", ret);
     return ret;
@@ -791,6 +807,8 @@ OCStackResult TWSwitchDoorLockState(char* nodeId, char* endpointId, char* newSta
             SEPARATOR_LENGTH + strlen(SENDMODE) +
             SEPARATOR_LENGTH + strlen(newState) + 1;
 
+    TWEntry* entry = NULL;
+
     char* cmdString = (char*)OICMalloc(size * sizeof(char));
     if (cmdString == NULL)
     {
@@ -821,7 +839,6 @@ OCStackResult TWSwitchDoorLockState(char* nodeId, char* endpointId, char* newSta
 
     OIC_LOG_V(INFO, TAG, "Write %s", cmdString);
 
-    TWEntry* entry = NULL;
     twRet = TWDequeueEntry(ctx->g_plugin, &entry, TW_DFTREP);
     if (twRet != TW_RESULT_OK)
     {
@@ -848,7 +865,10 @@ OCStackResult TWSwitchDoorLockState(char* nodeId, char* endpointId, char* newSta
     ret = OC_STACK_OK;
 
 exit:
-    TWDeleteEntry(ctx->g_plugin, entry);
+    if (entry != NULL)
+    {
+        TWDeleteEntry(ctx->g_plugin, entry);
+    }
     OICFree(cmdString);
     OIC_LOG_V(INFO, TAG, "Leave TWSwitchDoorLockState() with ret=%d", ret);
     return ret;
@@ -882,6 +902,8 @@ OCStackResult TWColorMoveToColorTemperature(char* nodeId, char* endpointId,
             SEPARATOR_LENGTH + strlen(colorTemperature) +
             SEPARATOR_LENGTH + strlen(transTime) + 1;
 
+    TWEntry* entry = NULL;
+
     char* cmdString = (char*)OICMalloc(size * sizeof(char));
     if (cmdString == NULL)
     {
@@ -911,7 +933,6 @@ OCStackResult TWColorMoveToColorTemperature(char* nodeId, char* endpointId,
     }
     OIC_LOG_V(INFO, TAG, "Write %s", cmdString);
 
-    TWEntry* entry = NULL;
     twRet = TWDequeueEntry(ctx->g_plugin, &entry, TW_DFTREP);
     if (twRet != TW_RESULT_OK)
     {
@@ -937,7 +958,10 @@ OCStackResult TWColorMoveToColorTemperature(char* nodeId, char* endpointId,
     ret = OC_STACK_OK;
 
 exit:
-    TWDeleteEntry(ctx->g_plugin, entry);
+    if (entry != NULL)
+    {
+        TWDeleteEntry(ctx->g_plugin, entry);
+    }
     OICFree(cmdString);
     OIC_LOG_V(INFO, TAG, "Leave TWColorMoveToColorTemperature() with ret=%d", ret);
     return ret;
@@ -1710,6 +1734,8 @@ TWResultCode CreatePAN(TWContext* ctx)
 
     OIC_LOG(INFO, TAG, "Enter CreatePAN()");
 
+    TWEntry* entry = NULL;
+    TWEntry* entry2 = NULL;
     TWResultCode twRet1 = TW_RESULT_UNKNOWN;
     TWResultCode twRet2 = TW_RESULT_UNKNOWN;
     TWResultCode ret = TW_RESULT_UNKNOWN;
@@ -1720,8 +1746,6 @@ TWResultCode CreatePAN(TWContext* ctx)
         goto exit;
     }
     OIC_LOG_V(INFO, TAG, "Write %s", AT_CMD_GET_NETWORK_INFO);
-    TWEntry* entry = NULL;
-    TWEntry* entry2 = NULL;
     ret = TWDequeueEntry(ctx->g_plugin, &entry, TW_NETWORK_INFO);
     if (ret != TW_RESULT_OK)
     {
@@ -1782,7 +1806,7 @@ TWResultCode CreatePAN(TWContext* ctx)
     }
 
 exit:
-    if (entry)
+    if (entry != NULL)
     {
         twRet1 = TWDeleteEntry(ctx->g_plugin, entry);
         if(twRet1 != TW_RESULT_OK)
@@ -1950,6 +1974,8 @@ TWResultCode FindClusters(char nodeId[], char endpoint[], TWContext* ctx)
                SEPARATOR_LENGTH + strlen(nodeId) +
                SEPARATOR_LENGTH + strlen(endpoint) + 1;
 
+    TWEntry* entry = NULL;
+
     char* cmdString = (char*)OICMalloc(size * sizeof(char));
     if (cmdString == NULL)
     {
@@ -1977,7 +2003,6 @@ TWResultCode FindClusters(char nodeId[], char endpoint[], TWContext* ctx)
     }
     OIC_LOG_V(INFO, TAG, "Write %s", cmdString);
 
-    TWEntry* entry = NULL;
     ret = TWDequeueEntry(ctx->g_plugin, &entry, TW_SIMPLEDESC);
     if (ret != TW_RESULT_OK)
     {
@@ -2002,7 +2027,10 @@ TWResultCode FindClusters(char nodeId[], char endpoint[], TWContext* ctx)
     }
 
 exit:
-    TWDeleteEntry(ctx->g_plugin, entry);
+    if (entry != NULL)
+    {
+        TWDeleteEntry(ctx->g_plugin, entry);
+    }
     OICFree(cmdString);
     OIC_LOG_V(INFO, TAG, "Leave FindClusters() with ret=%d", ret);
     return ret;
@@ -2019,6 +2047,8 @@ TWResultCode GetRemoteEUI(char *nodeId, char* outRemoteEUI, TWContext* ctx)
 
     int size = strlen(AT_CMD_REMOTE_EUI_REQUEST) + strlen(nodeId) +
                SEPARATOR_LENGTH + strlen(nodeId) + 1;
+    TWEntry* entry = NULL;
+
     char* cmdString = (char*)OICMalloc(size * sizeof(char));
     if (cmdString == NULL)
     {
@@ -2045,7 +2075,6 @@ TWResultCode GetRemoteEUI(char *nodeId, char* outRemoteEUI, TWContext* ctx)
     }
     OIC_LOG_V(INFO, TAG, "Write %s", cmdString);
 
-    TWEntry* entry = NULL;
     ret = TWDequeueEntry(ctx->g_plugin, &entry, TW_ADDRESS_RESPONSE);
     if (ret != TW_RESULT_OK)
     {
@@ -2085,7 +2114,10 @@ TWResultCode GetRemoteEUI(char *nodeId, char* outRemoteEUI, TWContext* ctx)
 exit:
     memset(ctx->g_WIPRemoteEUI, '\0', sizeof(ctx->g_WIPRemoteEUI));
     memset(ctx->g_WIPRemoteNodeId, '\0', sizeof(ctx->g_WIPRemoteNodeId));
-    TWDeleteEntry(ctx->g_plugin, entry);
+    if (entry != NULL)
+    {
+        TWDeleteEntry(ctx->g_plugin, entry);
+    }
     OICFree(cmdString);
     OIC_LOG_V(INFO, TAG, "Leave GetRemoteEUI() with ret=%d", ret);
     return ret;
@@ -2537,7 +2569,7 @@ TWResultCode TelSimpleDescInClusterHandler(int count, char* tokens[], TWContext*
     {
         OIC_LOG(ERROR, TAG, "Invalid Params");
         ret = TW_RESULT_ERROR_INVALID_PARAMS;
-               goto exit;
+        goto exit;
     }
 
     if (ctx->g_WIPDevice == NULL)