Fix code whaich produced uninitialised space in the cells array.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@20905 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
CaS 2005-03-14 10:54:49 +00:00
parent 0080d96c65
commit a1f032b795
2 changed files with 39 additions and 16 deletions

View file

@ -1,4 +1,15 @@
2005-03-13 Richard Frith-Macdoanld <rfm@gnu.org> 2005-03-14 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSMatrix.m:
([removeRow:]) set column counts to zero if all rows are removed
([removeColumn:]) set row counts to zero if all columns are removed
([_renewRows:columns:rowSpace:colSpace:]) initialise all columns of
any newly created rows (up to _maxCols) rather than just the number
specified by the method argument. Otherwise we get uninitialised
columns in the matrix which will cause a crash when they are used.
Fixes bug #12299
2005-03-13 Richard Frith-Macdonald <rfm@gnu.org>
* Headers/AppKit/NSGraphics.h: Fix prototype for stricter compiler. * Headers/AppKit/NSGraphics.h: Fix prototype for stricter compiler.
* Source/Functions.m: ditto * Source/Functions.m: ditto

View file

@ -634,6 +634,11 @@ static SEL getSel;
_numCols--; _numCols--;
_maxCols--; _maxCols--;
if (_maxCols == 0)
{
_numRows = _maxRows = 0;
}
if (column == _selectedColumn) if (column == _selectedColumn)
{ {
_selectedCell = nil; _selectedCell = nil;
@ -680,6 +685,11 @@ static SEL getSel;
_maxRows--; _maxRows--;
_numRows--; _numRows--;
if (_maxRows == 0)
{
_numCols = _maxCols = 0;
}
if (row == _selectedRow) if (row == _selectedRow)
{ {
_selectedCell = nil; _selectedCell = nil;
@ -2204,7 +2214,7 @@ static SEL getSel;
// we clear the existing selection // we clear the existing selection
// unless the Alternate or Shift keys have been pressed. // unless the Alternate or Shift keys have been pressed.
if (!(mouseDownFlags & NSShiftKeyMask) if (!(mouseDownFlags & NSShiftKeyMask)
&& !(mouseDownFlags & NSAlternateKeyMask)) && !(mouseDownFlags & NSAlternateKeyMask))
{ {
[self deselectAllCells]; [self deselectAllCells];
} }
@ -3591,18 +3601,19 @@ static SEL getSel;
int end = row - 1; int end = row - 1;
_cells = NSZoneRealloc(_myZone, _cells, row * sizeof(id*)); _cells = NSZoneRealloc(_myZone, _cells, row * sizeof(id*));
_selectedCells = NSZoneRealloc(_myZone, _selectedCells, row * sizeof(BOOL*)); _selectedCells
= NSZoneRealloc(_myZone, _selectedCells, row * sizeof(BOOL*));
/* Allocate the new rows and fill them */ /* Allocate the new rows and fill them */
for (i = oldMaxR; i < row; i++) for (i = oldMaxR; i < row; i++)
{ {
_cells[i] = NSZoneMalloc(_myZone, col * sizeof(id)); _cells[i] = NSZoneMalloc(_myZone, _maxCols * sizeof(id));
_selectedCells[i] = NSZoneMalloc(GSAtomicMallocZone(), _selectedCells[i] = NSZoneMalloc(GSAtomicMallocZone(),
col * sizeof(BOOL)); _maxCols * sizeof(BOOL));
if (i == end) if (i == end)
{ {
for (j = 0; j < col; j++) for (j = 0; j < _maxCols; j++)
{ {
_cells[i][j] = nil; _cells[i][j] = nil;
_selectedCells[i][j] = NO; _selectedCells[i][j] = NO;
@ -3610,7 +3621,7 @@ static SEL getSel;
{ {
rowSpace--; rowSpace--;
} }
else else if (i < col)
{ {
(*mkImp)(self, mkSel, i, j); (*mkImp)(self, mkSel, i, j);
} }
@ -3618,11 +3629,14 @@ static SEL getSel;
} }
else else
{ {
for (j = 0; j < col; j++) for (j = 0; j < _maxCols; j++)
{ {
_cells[i][j] = nil; _cells[i][j] = nil;
_selectedCells[i][j] = NO; _selectedCells[i][j] = NO;
(*mkImp)(self, mkSel, i, j); if (i < col)
{
(*mkImp)(self, mkSel, i, j);
}
} }
} }
} }
@ -3665,9 +3679,9 @@ static SEL getSel;
NSCell *aCell = _cells[i][j]; NSCell *aCell = _cells[i][j];
if ([aCell isEnabled] if ([aCell isEnabled]
&& ([aCell state] != state || [aCell isHighlighted] != highlight && ([aCell state] != state || [aCell isHighlighted] != highlight
|| (state == NSOffState && _selectedCells[i][j] != NO) || (state == NSOffState && _selectedCells[i][j] != NO)
|| (state != NSOffState && _selectedCells[i][j] == NO))) || (state != NSOffState && _selectedCells[i][j] == NO)))
{ {
[aCell setState: state]; [aCell setState: state];
@ -3696,8 +3710,7 @@ static SEL getSel;
{ {
if ([_cells[row][j] isEnabled] && [_cells[row][j] isSelectable]) if ([_cells[row][j] isEnabled] && [_cells[row][j] isSelectable])
{ {
_selectedCell = [self selectTextAtRow: row _selectedCell = [self selectTextAtRow: row column: j];
column: j];
_selectedRow = row; _selectedRow = row;
_selectedColumn = j; _selectedColumn = j;
return YES; return YES;
@ -3711,8 +3724,7 @@ static SEL getSel;
{ {
if ([_cells[i][j] isEnabled] && [_cells[i][j] isSelectable]) if ([_cells[i][j] isEnabled] && [_cells[i][j] isSelectable])
{ {
_selectedCell = [self selectTextAtRow: i _selectedCell = [self selectTextAtRow: i column: j];
column: j];
_selectedRow = i; _selectedRow = i;
_selectedColumn = j; _selectedColumn = j;
return YES; return YES;