From 3966cd2fc200bfccd12fefd1d999e6f700fd17be Mon Sep 17 00:00:00 2001 From: Iain Patterson Date: Wed, 19 Jun 2013 17:35:09 +0100 Subject: [PATCH] Don't crash when SwitchPanelImages is None. The whole changeImage() function in switchpanel.c is a no-op if wPreferences.swtileImage is set to None because the panel isn't actually drawn in that case. As a consequence there are no images to change. As well as being logically incorrect the existing code causes a segfault if the user has the SwitchPanelImages preference set to None because changeImage() would attempt to access the icons and images arrays which are only initialised in wInitSwitchPanel() when swtileImage has a value. Bug report and diagnosis by Juan Giordana, Gabriel Vlasiu and Christophe Curis. --- src/switchpanel.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/switchpanel.c b/src/switchpanel.c index 62ced772..f616bfaf 100644 --- a/src/switchpanel.c +++ b/src/switchpanel.c @@ -112,11 +112,19 @@ static Bool sameWindowClass(WWindow *wwin, WWindow *curwin) static void changeImage(WSwitchPanel *panel, int idecks, int selected, Bool dim, Bool force) { - WMFrame *icon = WMGetFromArray(panel->icons, idecks); - RImage *image = WMGetFromArray(panel->images, idecks); - char flags = (char) (uintptr_t) WMGetFromArray(panel->flags, idecks); + WMFrame *icon = NULL; + RImage *image = NULL; + char flags = 0; char desired = 0; + /* This whole function is a no-op if we aren't drawing the panel */ + if (!wPreferences.swtileImage) + return; + + icon = WMGetFromArray(panel->icons, idecks); + image = WMGetFromArray(panel->images, idecks); + flags = (char) (uintptr_t) WMGetFromArray(panel->flags, idecks); + if (selected) desired |= ICON_SELECTED; if (dim)