]> git.saurik.com Git - wxWidgets.git/commitdiff
Don't use uninitialized variables in wxGrid::AutoSize().
authorVadim Zeitlin <vadim@wxwidgets.org>
Sun, 11 Jul 2010 10:44:12 +0000 (10:44 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sun, 11 Jul 2010 10:44:12 +0000 (10:44 +0000)
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

src/generic/grid.cpp

index 887ba87cf0526fbf5597d17e8eefc7a7e10c1df8..798ffce16eca3e36e785be885c1ba693aea83445 100644 (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