Don't use uninitialized variables in wxGrid::AutoSize().

The code in wxGrid::AutoSizeColOrRow() was using uninitialized col/row
variable if the grid had no rows/columns, resulting in assertion failures when
trying to automatically size the columns of an empty grid.

Do initialize them now and also remove duplicate assignments to the variables
which never change inside the loop.

Closes #12206.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@64885 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin 2010-07-11 10:44:12 +00:00
parent 3dea8ba7ac
commit 68abd97d19

View File

@ -7865,24 +7865,29 @@ wxGrid::AutoSizeColOrRow(int colOrRow, bool setAsMin, wxGridDirection direction)
HideCellEditControl();
SaveEditControlValue();
// initialize both of them just to avoid compiler warnings
int row = -1,
// initialize both of them just to avoid compiler warnings even if only
// really needs to be initialized here
int row,
col;
if ( column )
{
row = -1;
col = colOrRow;
}
else
{
row = colOrRow;
col = -1;
}
wxCoord extent, extentMax = 0;
int max = column ? m_numRows : m_numCols;
for ( int rowOrCol = 0; rowOrCol < max; rowOrCol++ )
{
if ( column )
{
row = rowOrCol;
col = colOrRow;
}
else
{
row = colOrRow;
col = rowOrCol;
}
// we need to account for the cells spanning multiple columns/rows:
// while they may need a lot of space, they don't need all of it in