Fix clearing selection in a grid with reordered columns
Since the changes of 04f7f1fd32
(frozen
rows/columns implementation), RefreshBlock() could call GetColPos() with
an invalid index. This didn't matter most of the time as the function
simply returned the same index as long as the columns were using their
natural order, but resulted in a crash due to an out of bound access to
m_colAt array as soon as they were reordered.
Fix this by avoiding using invalid indices in RefreshBlock() and, more
generally, improving its precondition check and making the assumptions
about the input parameters more clear. Also add a defensive check to
GetColPos() itself.
Finally, add a unit test exercising this code.
Closes https://github.com/wxWidgets/wxWidgets/pull/1536
This commit is contained in:
committed by
Vadim Zeitlin
parent
16b08c6ef9
commit
e2bd6ec8f7
@@ -1131,6 +1131,8 @@ public:
|
||||
const wxArrayString& lines,
|
||||
long *width, long *height ) const;
|
||||
|
||||
// If bottomRight is invalid, i.e. == wxGridNoCellCoords, it defaults to
|
||||
// topLeft. If topLeft itself is invalid, the function simply returns.
|
||||
void RefreshBlock(const wxGridCellCoords& topLeft,
|
||||
const wxGridCellCoords& bottomRight);
|
||||
|
||||
@@ -1522,6 +1524,8 @@ public:
|
||||
// reverse mapping currently
|
||||
int GetColPos(int idx) const
|
||||
{
|
||||
wxASSERT_MSG( idx >= 0 && idx < m_numCols, "invalid column index" );
|
||||
|
||||
if ( m_colAt.IsEmpty() )
|
||||
return idx;
|
||||
|
||||
|
Reference in New Issue
Block a user