From 371c36f8817780a913bc2c600c2204e61267972d Mon Sep 17 00:00:00 2001
From: Stefan Dombrowski <stefan@uni-bonn.de>
Date: Sun, 22 Aug 2010 20:16:15 +0200
Subject: Fixing segmentation fault when tab gets removed
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

How to reproduce the bug: Leave a party, while the party tab in the chat
window is not selected. Then click with the mouse on the chat window.

Signed-off-by: Thorbjørn Lindeijer <thorbjorn@lindeijer.nl>
---
 src/gui/widgets/tabbedarea.cpp | 20 +++-----------------
 1 file changed, 3 insertions(+), 17 deletions(-)

diff --git a/src/gui/widgets/tabbedarea.cpp b/src/gui/widgets/tabbedarea.cpp
index a774ab22..101c9546 100644
--- a/src/gui/widgets/tabbedarea.cpp
+++ b/src/gui/widgets/tabbedarea.cpp
@@ -103,16 +103,12 @@ void TabbedArea::addTab(const std::string &caption, gcn::Widget *widget)
 
 void TabbedArea::removeTab(Tab *tab)
 {
-    int tabIndexToBeSelected = -1;
-
     if (tab == mSelectedTab)
     {
-        int index = getSelectedTabIndex();
-
-        if (index == (int)mTabs.size() - 1 && mTabs.size() == 1)
-            tabIndexToBeSelected = -1;
+        if (getNumberOfTabs() > 1)
+            setSelectedTab(std::max(0, getSelectedTabIndex() - 1));
         else
-            tabIndexToBeSelected = index - 1;
+            mSelectedTab = 0;
     }
 
     TabContainer::iterator iter;
@@ -137,16 +133,6 @@ void TabbedArea::removeTab(Tab *tab)
         }
     }
 
-    if (tabIndexToBeSelected == -1)
-    {
-        mSelectedTab = NULL;
-        mWidgetContainer->clear();
-    }
-    else
-    {
-        setSelectedTab(tabIndexToBeSelected);
-    }
-
     adjustSize();
     adjustTabPositions();
 }
-- 
cgit v1.2.3-70-g09d2