Fix defect detected by static anlaysis tool 12/174512/2
authorInHong Han <inhong1.han@samsung.com>
Mon, 2 Apr 2018 11:43:51 +0000 (20:43 +0900)
committerInHong Han <inhong1.han@samsung.com>
Tue, 3 Apr 2018 01:07:23 +0000 (01:07 +0000)
Change-Id: I9ce40294ac796696821016ae459ba59a117aa2a4

ism/extras/efl_panel/isf_panel_efl.cpp
ism/extras/wayland_immodule/wayland_imcontext.c
ism/modules/panelagent/ecoresocket/ecore_socket_panel_agent_module.cpp
ism/modules/panelagent/wayland/wayland_panel_agent_module.cpp
ism/src/isf_imcontrol_client.cpp
ism/src/isf_query_utility.cpp
ism/src/scim_helper_launcher.cpp
ism/src/scim_utility.cpp

index 01798dd..4958248 100644 (file)
@@ -7697,7 +7697,7 @@ int main (int argc, char *argv [])
                 ret = -1;
                 goto cleanup;
             }
-            DebugOutput::set_output (argv [i]);
+            DebugOutput::set_output (String (argv [i]));
             continue;
         }
 
index edfe6b0..ac6df2d 100644 (file)
@@ -823,9 +823,6 @@ key_down_filter_cb(void *data EINA_UNUSED, int type EINA_UNUSED, void *event)
             LOGD("no focus");
 
         SECURE_LOGD ("%s key is pressed. ret : %d", ev->keyname, filter_ret);
-        if (filter_ret) {
-            return EINA_FALSE; /* the event is removed from the queue */
-        }
         return EINA_FALSE; /* the event is removed from the queue */
     }
     return EINA_TRUE; /* the event is kept */
index c4e856d..61a3b0f 100644 (file)
@@ -922,8 +922,8 @@ private:
 
         if (trans.write_to_socket(client_socket)
             && trans.read_from_socket(client_socket)
-            && trans.get_command(cmd) && cmd == SCIM_TRANS_CMD_REPLY) {
-            trans.get_data(imdata, len);
+            && trans.get_command(cmd) && cmd == SCIM_TRANS_CMD_REPLY
+            && trans.get_data(imdata, len)) {
             LOGD ("length of imdata is %d", len);
         } else {
             LOGW ("read imdata failed");
@@ -3168,22 +3168,14 @@ private:
                     if (m_info_manager->check_privilege_by_sockfd(client_id, IMEMANAGER_PRIVILEGE)) {
                         String strAppid;
                         uint32 nEnabled = 0;
-                        bool ret = true;
-                        //FIXME
-                        //ret need be checked
+
                         m_info_manager->is_helper_ise_enabled(client_id, strAppid, nEnabled);
                         Transaction trans;
                         Socket client_socket(client_id);
                         trans.clear();
                         trans.put_command(SCIM_TRANS_CMD_REPLY);
-
-                        if (ret) {
-                            trans.put_command(SCIM_TRANS_CMD_OK);
-                            trans.put_data(static_cast<uint32>(nEnabled));
-                        } else {
-                            trans.put_command(SCIM_TRANS_CMD_FAIL);
-                        }
-
+                        trans.put_command(SCIM_TRANS_CMD_OK);
+                        trans.put_data(static_cast<uint32>(nEnabled));
                         trans.write_to_socket(client_socket);
                     }
                     else {
index 229a86e..9d88744 100644 (file)
@@ -1281,7 +1281,8 @@ isf_wsc_context_del (WSCContextISF *wsc_ctx)
 
     if (context_scim->selection_text_fd_read_handler) {
         int fd = ecore_main_fd_handler_fd_get (context_scim->selection_text_fd_read_handler);
-        close (fd);
+        if (fd >= 0)
+            close (fd);
         ecore_main_fd_handler_del (context_scim->selection_text_fd_read_handler);
         context_scim->selection_text_fd_read_handler = NULL;
     }
@@ -1293,14 +1294,16 @@ isf_wsc_context_del (WSCContextISF *wsc_ctx)
 
     if (context_scim->surrounding_text_fd_read_handler) {
         int fd = ecore_main_fd_handler_fd_get (context_scim->surrounding_text_fd_read_handler);
-        close (fd);
+        if (fd >= 0)
+            close (fd);
         ecore_main_fd_handler_del (context_scim->surrounding_text_fd_read_handler);
         context_scim->surrounding_text_fd_read_handler = NULL;
     }
 
     if (context_scim->remote_surrounding_text_fd_read_handler) {
         int fd = ecore_main_fd_handler_fd_get (context_scim->remote_surrounding_text_fd_read_handler);
-        close (fd);
+        if (fd >= 0)
+            close (fd);
         ecore_main_fd_handler_del (context_scim->remote_surrounding_text_fd_read_handler);
         context_scim->remote_surrounding_text_fd_read_handler = NULL;
     }
@@ -1338,7 +1341,7 @@ isf_wsc_context_del (WSCContextISF *wsc_ctx)
         // we need set the focused_ic to this context temporary.
         WSCContextISF* old_focused = _focused_ic;
         _focused_ic = context_scim;
-        _focused_ic = old_focused;
+        context_scim = old_focused;
 
         if (context_scim == _focused_ic) {
             g_info_manager->socket_turn_off ();
@@ -2012,6 +2015,9 @@ remote_surrounding_text_fd_read_func (void* data, Ecore_Fd_Handler* fd_handler)
     WSCContextISF* wsc_ctx = (WSCContextISF*)data;
 
     int fd = ecore_main_fd_handler_fd_get (fd_handler);
+    if (fd < 0)
+            return ECORE_CALLBACK_RENEW;
+
     char buff[512];
     int len = read (fd, buff, sizeof (buff) - 1);
 
@@ -3266,7 +3272,8 @@ public:
 
         if (ic->surrounding_text_fd_read_handler) {
             int fd = ecore_main_fd_handler_fd_get (ic->surrounding_text_fd_read_handler);
-            close (fd);
+            if (fd >= 0)
+                close (fd);
             ecore_main_fd_handler_del (ic->surrounding_text_fd_read_handler);
             ic->surrounding_text_fd_read_handler = NULL;
         }
index 155fff5..edbf6f1 100644 (file)
@@ -425,11 +425,7 @@ public:
             return false;
         }
 
-        if (appid.size () > 0) {
-            m_trans.get_data (label);
-            m_trans.get_data (is_enabled);
-            m_trans.get_data (is_preinstalled);
-            m_trans.get_data (has_option);
+        if (appid.size () > 0 && m_trans.get_data (label) && m_trans.get_data (is_enabled) && m_trans.get_data (is_preinstalled) && m_trans.get_data (has_option)) {
             if (appid.size () == label.size () && appid.size () == is_enabled.size () && appid.size () == is_preinstalled.size () && appid.size () == has_option.size ()) {
                 info.appid = appid;
                 info.label = label;
index d65a81b..fe78fb4 100644 (file)
@@ -299,7 +299,8 @@ static inline int _db_connect(void)
             _db_disconnect();
             LOGD("need_reset, removing db");
             databaseInfo.need_reset = false;
-            remove(databaseInfo.pPath);
+            if (remove(databaseInfo.pPath) != 0)
+                LOGW ("Error deleting path");
             ret = _db_init();
         }
 
index fdc902b..5e16524 100644 (file)
@@ -145,7 +145,7 @@ int main (int argc, char *argv [])
         }
     }
 
-    String exec = String (argv[0]);
+    String exec = argv[0];
 
     if (exec != String (SCIM_HELPER_LAUNCHER_PROGRAM)) {
         /* 3rd party shared object type IME */
index ea076c0..fdab609 100644 (file)
@@ -681,9 +681,14 @@ scim_get_user_name ()
     char buf [2048] = {0,};
 
     setpwent ();
-    getpwuid_r (getuid (), &pw, buf, sizeof (buf), &result);
+    int ret = getpwuid_r (getuid (), &pw, buf, sizeof (buf), &result);
     endpwent ();
 
+    if (ret != 0 || !result) {
+        LOGE ("Fail to getpwuid_r");
+        return String ("");
+    }
+
     if (result && pw.pw_name) {
         return String (pw.pw_name);
     } else if ((user_name = getenv ("USER")) != NULL) {