[Xfce4-commits] <xfdesktop:master> Fix some more potential bugs

Eric Koegel noreply at xfce.org
Sat Jan 25 19:36:01 CET 2014


Updating branch refs/heads/master
         to 3aeedbb076b1315b56e43e798694425657569abe (commit)
       from cad4ddfa7d735b62099c9716e99821536a02b006 (commit)

commit 3aeedbb076b1315b56e43e798694425657569abe
Author: Eric Koegel <eric.koegel at gmail.com>
Date:   Sat Jan 25 21:32:26 2014 +0300

    Fix some more potential bugs
    
    An unchecked return value, unintended sign extensions, and a copy
    paste error.

 src/xfdesktop-file-icon-manager.c |    2 +-
 src/xfdesktop-icon-view.c         |   27 ++++++++++++++++-----------
 2 files changed, 17 insertions(+), 12 deletions(-)

diff --git a/src/xfdesktop-file-icon-manager.c b/src/xfdesktop-file-icon-manager.c
index 7870635..9e9ad3c 100644
--- a/src/xfdesktop-file-icon-manager.c
+++ b/src/xfdesktop-file-icon-manager.c
@@ -2487,7 +2487,7 @@ xfdesktop_file_icon_manager_file_changed(GFileMonitor     *monitor,
             if(moved_icon) {
                 /* Since we're replacing an existing icon, get that location
                  * to use instead */
-                if(!xfdesktop_icon_get_position(XFDESKTOP_ICON(icon), &row, &col)) {
+                if(!xfdesktop_icon_get_position(XFDESKTOP_ICON(moved_icon), &row, &col)) {
                     /* Failed to get position... not supported? */
                     row = col = 0;
                 }
diff --git a/src/xfdesktop-icon-view.c b/src/xfdesktop-icon-view.c
index 5b81528..03c5acd 100644
--- a/src/xfdesktop-icon-view.c
+++ b/src/xfdesktop-icon-view.c
@@ -2680,10 +2680,10 @@ static void
 xfdesktop_setup_grids(XfdesktopIconView *icon_view)
 {
     gint xorigin = 0, yorigin = 0, width = 0, height = 0;
+    guint total_cells = (guint)icon_view->priv->nrows * icon_view->priv->ncols;
     gsize old_size, new_size;
     
-    old_size = icon_view->priv->nrows * icon_view->priv->ncols
-               * sizeof(XfdesktopIcon *);
+    old_size = total_cells * sizeof(XfdesktopIcon *);
     
     if(!xfdesktop_get_workarea_single(icon_view, 0,
                                       &xorigin, &yorigin,
@@ -2705,10 +2705,12 @@ xfdesktop_setup_grids(XfdesktopIconView *icon_view)
         
     DBG("CELL_SIZE=%0.3f, TEXT_WIDTH=%0.3f, ICON_SIZE=%u", CELL_SIZE, TEXT_WIDTH, ICON_SIZE);
     DBG("grid size is %dx%d", icon_view->priv->nrows, icon_view->priv->ncols);
-    
-    new_size = icon_view->priv->nrows * icon_view->priv->ncols
-               * sizeof(XfdesktopIcon *);
-    
+
+    /* recalculate */
+    total_cells = (guint)icon_view->priv->nrows * icon_view->priv->ncols;
+
+    new_size = total_cells * sizeof(XfdesktopIcon *);
+
     if(icon_view->priv->grid_layout) {
         icon_view->priv->grid_layout = g_realloc(icon_view->priv->grid_layout,
                                                  new_size);
@@ -3217,6 +3219,7 @@ static void
 xfdesktop_move_all_icons_to_pending_icons_list(XfdesktopIconView *icon_view)
 {
     GList *l = NULL;
+    guint total_cells = (guint)icon_view->priv->nrows * icon_view->priv->ncols;
     
     /* move all icons into the pending_icons list and remove from the desktop */
     for(l = icon_view->priv->icons; l; l = l->next) {
@@ -3234,8 +3237,7 @@ xfdesktop_move_all_icons_to_pending_icons_list(XfdesktopIconView *icon_view)
     icon_view->priv->icons = NULL;
 
     memset(icon_view->priv->grid_layout, 0,
-           icon_view->priv->nrows * icon_view->priv->ncols
-           * sizeof(XfdesktopIcon *));
+           total_cells * sizeof(XfdesktopIcon *));
     
     xfdesktop_setup_grids(icon_view);
 }
@@ -3312,7 +3314,9 @@ xfdesktop_move_all_previous_icons_to_desktop(XfdesktopIconView *icon_view)
         guint16 row, col;
         XfdesktopIcon *icon = XFDESKTOP_ICON(l->data);
 
-        xfdesktop_icon_get_position(icon, &row, &col);
+        if(!xfdesktop_icon_get_position(icon, &row, &col)) {
+            g_warning("Trying to set previous position of an icon with no position");
+        }
 
         if(xfdesktop_grid_is_free_position(icon_view, row, col)) {
             DBG("adding icon %s position row %d x col %d",
@@ -3369,6 +3373,8 @@ xfdesktop_move_all_pending_icons_to_desktop(XfdesktopIconView *icon_view)
 static void
 xfdesktop_grid_do_resize(XfdesktopIconView *icon_view)
 {
+    guint total_cells = (guint)icon_view->priv->nrows * icon_view->priv->ncols;
+
     xfdesktop_move_all_icons_to_pending_icons_list(icon_view);
 
 #if 0 /*def DEBUG*/
@@ -3376,8 +3382,7 @@ xfdesktop_grid_do_resize(XfdesktopIconView *icon_view)
 #endif
 
     memset(icon_view->priv->grid_layout, 0,
-           icon_view->priv->nrows * icon_view->priv->ncols
-           * sizeof(XfdesktopIcon *));
+           total_cells * sizeof(XfdesktopIcon *));
     
     xfdesktop_setup_grids(icon_view);
 


More information about the Xfce4-commits mailing list