[IOT-2513]NS Fix for static analyzer issues 27/21527/4
authorabitha.s <abitha.s@samsung.com>
Tue, 18 Jul 2017 10:44:10 +0000 (16:14 +0530)
committerUze Choi <uzchoi@samsung.com>
Thu, 20 Jul 2017 12:15:00 +0000 (12:15 +0000)
1. Removal of Null dereferences.
2. Adding field width specifiers.
3. removing negative checks on unsigned int.

Change-Id: I086c57f3a2473895cd424856f1e9e71af89e10d1
Signed-off-by: abitha.s <abitha.s@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/21515
Tested-by: jenkins-iotivity <jenkins@iotivity.org>
Reviewed-by: Uze Choi <uzchoi@samsung.com>
(cherry picked from commit 17afad03deea12a1d61e1bdc758514313109e61e)
Reviewed-on: https://gerrit.iotivity.org/gerrit/21527

service/notification/cpp-wrapper/consumer/src/NSConsumerService.cpp
service/notification/cpp-wrapper/consumer/src/NSProvider.cpp
service/notification/examples/linux/notificationconsumer.c
service/notification/examples/linux/notificationprovider.c
service/notification/src/common/NSUtil.c
service/notification/src/provider/NSProviderNotification.c

index fdfac60..e900f73 100644 (file)
@@ -134,12 +134,9 @@ namespace OIC
                         while (iter)
                         {
                             following = iter->next;
-                            if (iter)
-                            {
-                                NSOICFree(iter->topicName);
-                                iter->next = NULL;
-                                NSOICFree(iter);
-                            }
+                            NSOICFree(iter->topicName);
+                            iter->next = NULL;
+                            NSOICFree(iter);
                             iter = following;
                         }
                     }
index cc1e546..3478d30 100644 (file)
@@ -183,12 +183,9 @@ namespace OIC
                 while (iter)\r
                 {\r
                     following = iter->next;\r
-                    if (iter)\r
-                    {\r
-                        NSOICFree(iter->topicName);\r
-                        iter->next = NULL;\r
-                        NSOICFree(iter);\r
-                    }\r
+                    NSOICFree(iter->topicName);\r
+                    iter->next = NULL;\r
+                    NSOICFree(iter);\r
                     iter = following;\r
                 }\r
             }\r
index 9e97e3c..1198fdc 100644 (file)
@@ -193,7 +193,7 @@ int main(void)
 
         printf("Input: ");
 
-        if(scanf("%d", &num) == EOF)
+        if(scanf("%2d", &num) == EOF)
         {
             printf("Fail to input num\n");
         }
index b2e9fd3..f777ede 100644 (file)
@@ -207,7 +207,7 @@ int main()
 
         printf("input : ");
 
-        if(scanf("%d", &num) > 0)
+        if(scanf("%2d", &num) > 0)
         {
             if(scanf("%c", &dummy) > 0)
             {
index 2fbc027..3d9f73e 100644 (file)
@@ -205,7 +205,6 @@ NSResult NSFreeConsumer(NSConsumer * obj)
     (obj->consumerId)[0] = '\0';
 
     OICFree(obj);
-    obj = NULL;
 
     return NS_OK;
 }
@@ -490,7 +489,7 @@ OCDevAddr * NSChangeAddress(const char * inputaddress)
     {
         address = schema + 2;
     }
-    size_t prefixLen = schema - inputaddress;
+    int prefixLen = schema - inputaddress;
     if (prefixLen <= 0)
     {
         NS_LOG(ERROR, "Invalid Input address.");
index cc7cbbb..f97ef2c 100644 (file)
@@ -90,7 +90,7 @@ OCStackResult NSProviderPublishTopic(OCRepPayload * payload, OCClientResponseHan
 
     NSMQServerInfo * serverInfo = NSGetMQServerInfo();
 
-    if (!serverInfo)
+    if (serverInfo)
     {
         NS_LOG(DEBUG, "serverInfo is not NULL");
         NS_LOG_V(DEBUG, "serverInfo->serverUri = %s", serverInfo->serverUri);