From ba768efaf3d9781ac59cf2ecc0854a55b108e574 Mon Sep 17 00:00:00 2001 From: "abitha.s" Date: Tue, 18 Jul 2017 16:14:10 +0530 Subject: [PATCH] [IOT-2513]NS Fix for static analyzer issues 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 Reviewed-on: https://gerrit.iotivity.org/gerrit/21515 Tested-by: jenkins-iotivity Reviewed-by: Uze Choi (cherry picked from commit 17afad03deea12a1d61e1bdc758514313109e61e) Reviewed-on: https://gerrit.iotivity.org/gerrit/21527 --- .../notification/cpp-wrapper/consumer/src/NSConsumerService.cpp | 9 +++------ service/notification/cpp-wrapper/consumer/src/NSProvider.cpp | 9 +++------ service/notification/examples/linux/notificationconsumer.c | 2 +- service/notification/examples/linux/notificationprovider.c | 2 +- service/notification/src/common/NSUtil.c | 3 +-- service/notification/src/provider/NSProviderNotification.c | 2 +- 6 files changed, 10 insertions(+), 17 deletions(-) diff --git a/service/notification/cpp-wrapper/consumer/src/NSConsumerService.cpp b/service/notification/cpp-wrapper/consumer/src/NSConsumerService.cpp index fdfac60..e900f73 100644 --- a/service/notification/cpp-wrapper/consumer/src/NSConsumerService.cpp +++ b/service/notification/cpp-wrapper/consumer/src/NSConsumerService.cpp @@ -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; } } diff --git a/service/notification/cpp-wrapper/consumer/src/NSProvider.cpp b/service/notification/cpp-wrapper/consumer/src/NSProvider.cpp index cc1e546..3478d30 100644 --- a/service/notification/cpp-wrapper/consumer/src/NSProvider.cpp +++ b/service/notification/cpp-wrapper/consumer/src/NSProvider.cpp @@ -183,12 +183,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; } } diff --git a/service/notification/examples/linux/notificationconsumer.c b/service/notification/examples/linux/notificationconsumer.c index 9e97e3c..1198fdc 100644 --- a/service/notification/examples/linux/notificationconsumer.c +++ b/service/notification/examples/linux/notificationconsumer.c @@ -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"); } diff --git a/service/notification/examples/linux/notificationprovider.c b/service/notification/examples/linux/notificationprovider.c index b2e9fd3..f777ede 100644 --- a/service/notification/examples/linux/notificationprovider.c +++ b/service/notification/examples/linux/notificationprovider.c @@ -207,7 +207,7 @@ int main() printf("input : "); - if(scanf("%d", &num) > 0) + if(scanf("%2d", &num) > 0) { if(scanf("%c", &dummy) > 0) { diff --git a/service/notification/src/common/NSUtil.c b/service/notification/src/common/NSUtil.c index 2fbc027..3d9f73e 100644 --- a/service/notification/src/common/NSUtil.c +++ b/service/notification/src/common/NSUtil.c @@ -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."); diff --git a/service/notification/src/provider/NSProviderNotification.c b/service/notification/src/provider/NSProviderNotification.c index cc7cbbb..f97ef2c 100644 --- a/service/notification/src/provider/NSProviderNotification.c +++ b/service/notification/src/provider/NSProviderNotification.c @@ -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); -- 2.7.4