Fixes the off-by-one bug in RegisterInGrid(), which caused dtfile's desktop icons...
authorEugene Doudine <dudinea@gmail.com>
Tue, 15 Apr 2014 13:50:21 +0000 (16:50 +0300)
committerJon Trulson <jon@radscan.com>
Sun, 20 Apr 2014 00:57:57 +0000 (18:57 -0600)
On small screens segfaults could be also triggered without any icons on dtfile
startup if dtwm panel (or part of it) was registered beyond the screen when
RegisterInGrid() was called by InitializeDesktopGrid().

The patch also makes grid registration work for large objects (larger than
2 cells in any direction, like dtwm panel or icon with long file name).
Previously only rectangle vertices were registered.

cde/programs/dtfile/Desktop.c

index f83c29f480fc7c9da3832c101db0935cfa6c07a6..fd07539722e46719deb0b8f453c9d488a3d3999f 100644 (file)
@@ -2487,6 +2487,7 @@ RegisterInGrid(
    int row, column;
    int rowHeight, columnWidth;
    int desktop_grid_index;
+   int i,j;
 
    if(desktopIconType == LARGE)
    {
@@ -2503,16 +2504,24 @@ RegisterInGrid(
       columnWidth = (rX + width) / PIXELS_PER_COLUMN_SMALL;
    }
 
+   if (columnWidth >= numColumns)
+   {
+      columnWidth = numColumns - 1;
+   }
+   if (rowHeight >= numRows)
+   {
+      rowHeight = numRows - 1;
+   }
+
    desktop_grid_index = (workspace - 1) * numColumns * numRows;
-   if(column < numColumns && row < numRows)
-     desktop_grid[ desktop_grid_index + (column * numRows) + row] = type;
-   if(rowHeight < numRows)
-      desktop_grid[desktop_grid_index + (column * numRows) + rowHeight] = type;
-   if(columnWidth < numColumns)
-      desktop_grid[desktop_grid_index + (columnWidth * numRows) + row] = type;
-   if(rowHeight < numRows && columnWidth < numColumns)
-      desktop_grid[desktop_grid_index +
-                                   (columnWidth * numRows) + rowHeight] = type;
+
+   for (i = (column > 0) ? column : 0; i <= columnWidth ; i++)
+   {
+      for (j = (row > 0) ? row : 0; j <= rowHeight ; j++)
+      {
+        desktop_grid[ desktop_grid_index + (i * numRows) + j] = type;
+      }
+   }
 }