Fix the problems detected by static analyzer 71/63271/1
authorGwanglim Lee <gl77.lee@samsung.com>
Wed, 23 Mar 2016 04:58:48 +0000 (13:58 +0900)
committerGwanglim Lee <gl77.lee@samsung.com>
Wed, 23 Mar 2016 04:58:48 +0000 (13:58 +0900)
Change-Id: Ibb4c6b496ba2a67cd8f2d2c16a30509cc5d2e2d7

src/bin/e_comp.c
src/bin/e_comp_wl.c
src/bin/e_comp_wl_input.c
src/bin/e_info_server.c
src/bin/e_path.c
src/bin/e_pixmap.c
src/bin/e_randr2.c
src/modules/wl_drm/e_mod_main.c

index 0d1c93c..e220cb1 100644 (file)
@@ -1070,12 +1070,13 @@ _e_launchscreen_new(Ecore_Evas *ee)
    E_Launch_Screen *plscrn = NULL;
 
    EINA_SAFETY_ON_NULL_GOTO(ee, error);
+   EINA_SAFETY_ON_NULL_GOTO(conf, error);
 
-   if ((conf) && (conf->launch_file))
+   if (conf->launch_file)
      {
-        if(!edje_file_group_exists(conf->launch_file, "e/comp/effects/launch"))
-           goto error;
-   }
+        if (!edje_file_group_exists(conf->launch_file, "e/comp/effects/launch"))
+          goto error;
+     }
 
    plscrn = E_NEW(E_Launch_Screen, 1);
    EINA_SAFETY_ON_NULL_GOTO(plscrn, error);
index 78011a8..e2bc451 100644 (file)
@@ -3395,7 +3395,7 @@ _e_comp_wl_screenshooter_cb_shoot(struct wl_client *client EINA_UNUSED, struct w
    E_Comp_Wl_Buffer *buffer;
    struct wl_shm_buffer *shm_buffer;
    int stride;
-   void *pixels, *d;
+   void *pixels = NULL, *d;
 
    output = wl_resource_get_user_data(output_resource);
    buffer = e_comp_wl_buffer_get(buffer_resource, NULL);
@@ -3430,6 +3430,7 @@ _e_comp_wl_screenshooter_cb_shoot(struct wl_client *client EINA_UNUSED, struct w
    if (!shm_buffer)
      {
         ERR("Could not get shm_buffer from resource");
+        free(pixels);
         return;
      }
 
@@ -3438,6 +3439,7 @@ _e_comp_wl_screenshooter_cb_shoot(struct wl_client *client EINA_UNUSED, struct w
    if (!d)
      {
         ERR("Could not get buffer data");
+        free(pixels);
         return;
      }
 
index de81e85..63f4b34 100644 (file)
@@ -376,8 +376,8 @@ _e_comp_wl_input_keymap_fd_get(off_t size)
    len = strlen(path);
    if (len < blen)
      {
-        strcpy(tmp, path);
-        strcat(tmp, "/e-wl-keymap-XXXXXX");
+        strncpy(tmp, path, len);
+        strncat(tmp, "/e-wl-keymap-XXXXXX", 19);
      }
    else
      return -1;
@@ -489,7 +489,7 @@ _e_comp_wl_input_keymap_update(struct xkb_keymap *keymap, const char *keymap_pat
         return;
      }
 
-   strcpy(e_comp_wl->xkb.area, tmp);
+   strncpy(e_comp_wl->xkb.area, e_comp_wl->xkb.size - 1);
    free(tmp);
 
    /* send updated keymap */
index a7b0463..5d8d464 100644 (file)
@@ -313,7 +313,7 @@ _msg_window_prop_client_append(Eldbus_Message_Iter *iter, E_Client *target_ec)
           {
              char temp[16];
              snprintf(temp, sizeof(temp), "0x%x", e_client_util_win_get(child));
-             strncat( transients, temp, sizeof(transients) - strlen(transients));
+             strncat(transients, temp, sizeof(transients) - strlen(transients));
           }
      }
 
@@ -325,7 +325,7 @@ _msg_window_prop_client_append(Eldbus_Message_Iter *iter, E_Client *target_ec)
              char temp[32];
              snprintf(temp, sizeof(temp), "[%d,%d,%d,%d] ", target_ec->shape_rects[i].x, target_ec->shape_rects[i].y,
                       target_ec->shape_rects[i].w, target_ec->shape_rects[i].h);
-             strncat( shape_rects, temp, sizeof(shape_rects) - strlen(shape_rects));
+             strncat(shape_rects, temp, sizeof(shape_rects) - strlen(shape_rects));
           }
      }
 
@@ -337,7 +337,7 @@ _msg_window_prop_client_append(Eldbus_Message_Iter *iter, E_Client *target_ec)
              char temp[32];
              snprintf(temp, sizeof(temp), "[%d,%d,%d,%d] ", target_ec->shape_input_rects[i].x, target_ec->shape_input_rects[i].y,
                       target_ec->shape_input_rects[i].w, target_ec->shape_input_rects[i].h);
-             strncat( shape_input, temp, sizeof(shape_input) - strlen(shape_input));
+             strncat(shape_input, temp, sizeof(shape_input) - strlen(shape_input));
           }
      }
 
@@ -655,7 +655,7 @@ _e_info_server_cb_rotation_message(const Eldbus_Service_Interface *iface EINA_UN
    if (rot_msg == E_INFO_ROTATION_MESSAGE_SET)
      {
         /* check if rval is valid */
-        if ((rval < 0) || (rval > 270) || (rval % 90 != 0))
+        if ((rval > 270) || (rval % 90 != 0))
           return reply;
      }
 
index b4b5484..7f8c8f7 100644 (file)
@@ -40,8 +40,8 @@ e_path_default_path_append(E_Path *ep, const char *path)
              return;
           }
 
-        strcpy(new_path, home_dir);
-        strcat(new_path, path + 1);
+        strncpy(new_path, home_dir, len1);
+        strncat(new_path, path + 1, len1 + len2);
         epd->dir = eina_stringshare_add(new_path);
         free(new_path);
         ep->default_dir_list = eina_list_append(ep->default_dir_list, epd);
@@ -93,8 +93,8 @@ e_path_user_path_append(E_Path *ep, const char *path)
              return;
           }
 
-        strcpy(new_path, home_dir);
-        strcat(new_path, path + 1);
+        strncpy(new_path, home_dir, len1);
+        strncat(new_path, path + 1, len1 + len2);
         epd->dir = eina_stringshare_add(new_path);
         free(new_path);
         *(ep->user_dir_list) = eina_list_append(*(ep->user_dir_list), epd);
@@ -136,8 +136,8 @@ e_path_user_path_prepend(E_Path *ep, const char *path)
              return;
           }
 
-        strcpy(new_path, home_dir);
-        strcat(new_path, path + 1);
+        strncpy(new_path, home_dir, len1);
+        strncat(new_path, path + 1, len1 + len2);
         epd->dir = eina_stringshare_add(new_path);
         free(new_path);
         *(ep->user_dir_list) = eina_list_prepend(*(ep->user_dir_list), epd);
@@ -174,8 +174,8 @@ e_path_user_path_remove(E_Path *ep, const char *path)
         len2 = strlen(path);
         new_path = malloc(len1 + len2 + 1);
         if (!new_path) return;
-        strcpy(new_path, home_dir);
-        strcat(new_path, path + 1);
+        strncpy(new_path, home_dir, len1);
+        strncat(new_path, path + 1, len1 + len2);
         EINA_LIST_FOREACH(*(ep->user_dir_list), l, epd)
           {
              if (epd->dir)
index ea9ad4b..648b0c2 100644 (file)
@@ -338,6 +338,8 @@ e_pixmap_new(E_Pixmap_Type type, ...)
         else
           pixmaps[type] = eina_hash_int32_new((Eina_Free_Cb)_e_pixmap_free);
         cp = _e_pixmap_new(type);
+        EINA_SAFETY_ON_NULL_RETURN_VAL(cp, NULL);
+
         cp->win = xwin;
         eina_hash_add(pixmaps[type], &xwin, cp);
 #endif
@@ -361,6 +363,8 @@ e_pixmap_new(E_Pixmap_Type type, ...)
           }
 
         cp = _e_pixmap_new(type);
+        EINA_SAFETY_ON_NULL_RETURN_VAL(cp, NULL);
+
         cp->win = id;
         eina_hash_add(pixmaps[type], &id, cp);
         uuid_generate(cp->uuid);
index 02a2ea2..a004eff 100644 (file)
@@ -669,7 +669,7 @@ _screen_fuzzy_fallback_find(E_Config_Randr2 *cfg, const char *id)
    // and fall back to finding just the output name in the rel
    // to identifier, rather than the specific screen id
    name = alloca(strlen(id) + 1);
-   strcpy(name, id);
+   strncpy(name, id, strlen(id));
    if ((p = strchr(name, '/'))) *p = 0;
 
    s = _screen_id_find(id);
@@ -695,7 +695,7 @@ _config_screen_clone_resolve(E_Config_Randr2 *cfg, const char *id, int *x, int *
    if (!cs) return NULL;
 
    name = alloca(strlen(cs->id) + 1);
-   strcpy(name, cs->id);
+   strncpy(name, cs->id, strlen(cs->id));
    if ((p = strchr(name, '/'))) *p = 0;
 
    s = _screen_id_find(cs->id);
index 83ebfb1..ec32784 100644 (file)
@@ -445,8 +445,8 @@ _drm_randr_create(void)
                   free(s);
                   continue;
                }
-             strcpy(s->id, s->info.name);
-             strcat(s->id, "/");
+             strncpy(s->id, s->info.name, strlen(s->info.name));
+             strncat(s->id, "/", 1);
              if (s->info.edid) strcat(s->id, s->info.edid);
 
              printf("DRM RRR: Created Screen: %s\n", s->id);