From 8bafd85d9a9daa9426d8ba3dc6a6a3f4ca16afd6 Mon Sep 17 00:00:00 2001 From: Eugene Doudine Date: Tue, 15 Apr 2014 16:50:21 +0300 Subject: [PATCH] Fixes the off-by-one bug in RegisterInGrid(), which caused dtfile's desktop icons on the right edge of the screen (if desktop width is not a multiple of icon with) to be registered on the next workspace or (in the case of the last workspace) beyond the desktop_grid array (possibly causing segfaults). 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 | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/cde/programs/dtfile/Desktop.c b/cde/programs/dtfile/Desktop.c index f83c29f4..fd075397 100644 --- a/cde/programs/dtfile/Desktop.c +++ b/cde/programs/dtfile/Desktop.c @@ -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; + } + } } -- 2.25.1