Fix for defects detected by static analysis in Scene Utils/Samples.
authorjyong2.kim <jyong2.kim@samsung.com>
Mon, 29 Feb 2016 09:21:40 +0000 (18:21 +0900)
committerHabib Virji <habib.virji@samsung.com>
Wed, 2 Mar 2016 06:43:36 +0000 (06:43 +0000)
Check to allocated memory using OICMalloc().
Fix execution with path of system command.
Catch exception in Sample app'.

Change-Id: I313d5a3fadf473f6cac355cb0b8cc5e49248dea0
Signed-off-by: jyong2.kim <jyong2.kim@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/5265
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Habib Virji <habib.virji@samsung.com>
service/scene-manager/sampleapp/linux/sceneclient.cpp
service/scene-manager/sampleapp/linux/sceneserver.cpp
service/scene-manager/src/SceneUtils.cpp

index ea2ff94..d2f50ab 100644 (file)
@@ -226,7 +226,7 @@ void configurePlatform()
     OCPlatform::Configure(config);
 }
 
-int processUserInput(int min, int max)
+void processUserInput(int min, int max)
 {
     assert(min <= max);
 
@@ -237,7 +237,7 @@ int processUserInput(int min, int max)
     if (!std::cin.fail())
     {
         if (input == max + 1)  exit(0);
-        if (min <= input && input <= max) return input;
+        if (min <= input && input <= max) return;
     }
 
     std::cin.clear();
@@ -253,8 +253,15 @@ void excecuteCommand(std::string str, Run runFunc)
     std::cout << "2. Quit         \n";
     std::cout << "========================================================  \n";
 
-    processUserInput(1, numMenu);
-    runFunc();
+    try
+    {
+        processUserInput(1, numMenu);
+        runFunc();
+    }
+    catch(std::exception & e)
+    {
+        std::cout << e.what() << std::endl;
+    }
 }
 
 void runMenu(Menu menu)
@@ -397,13 +404,29 @@ int main()
 {
     configurePlatform();
 
-    discoverResource();
+    try
+    {
+        discoverResource();
+    }
+    catch(std::exception &e)
+    {
+        std::cout << e.what() << std::endl;
+        return 0;
+    }
 
-    runMenu(CREATE_REMOTE_SCENE_LIST);
+    try
+    {
+        runMenu(CREATE_REMOTE_SCENE_LIST);
+    }
+    catch(std::exception &e)
+    {
+        std::cout << e.what() << std::endl;
+        return 0;
+    }
 
     while (true) { }
 
     std::cout << "Stopping the scene client" << std::endl;
 
     return 0;
-}
\ No newline at end of file
+}
index cfef6ae..a865d11 100755 (executable)
@@ -169,7 +169,7 @@ void displayClear(Run runFunc)
     std::cin.ignore();
     if(std::cin.get() == '\n')
     {
-        auto ret = std::system("clear");
+        auto ret = std::system("/usr/bin/clear");
         if(ret == -1)
         {
             std::cout << "clear error!" << std::endl;
index b2000f6..27eff03 100644 (file)
@@ -76,6 +76,11 @@ namespace OIC
         {
             CAEndpoint_t ** netInfo = (CAEndpoint_t **)OICMalloc(sizeof(CAEndpoint_t*)*5);
 
+            if(netInfo == nullptr)
+            {
+                throw RCSException("memory allocation fail");
+            }
+
             uint32_t size = 0;
             CAGetNetworkInformation(netInfo, &size);
 
@@ -121,5 +126,6 @@ namespace OIC
                 throw RCSException("Fail to create RCSResourceObject");
             }
         }
+
     }
 }