From: Eugene Doudine Date: Tue, 15 Apr 2014 13:50:21 +0000 (+0300) Subject: Fixes the off-by-one bug in RegisterInGrid(), which caused dtfile's desktop icons... X-Git-Tag: 2.2.2~13 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=8bafd85d9a9daa9426d8ba3dc6a6a3f4ca16afd6;p=oweals%2Fcde.git 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. --- 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; + } + } }