From e498a8bd79403a96dd5b9835b62ce1d1d9116c9f Mon Sep 17 00:00:00 2001 From: Christophe CURIS Date: Thu, 31 May 2012 20:26:09 +0200 Subject: [PATCH] Fixed possible off-by-one loops Due to variable size definitions in the structure, the 'for' loops may actually try to work on wrong data. Instead of using hard-coded value, we now simply let the compiler give us the number of elements. This may (or may not) fix a crash reported by Rodolfo kix Garcia. --- src/winspector.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/src/winspector.c b/src/winspector.c index 37ae0b2e..a5857104 100644 --- a/src/winspector.c +++ b/src/winspector.c @@ -884,7 +884,7 @@ static void revertSettings(WMButton * button, InspectorPanel * panel) wWindowSetupInitialAttributes(wwin, &level, &workspace); - for (i = 0; i < 11; i++) { + for (i = 0; i < (sizeof(panel->attrChk) / sizeof(panel->attrChk[0])); i++) { int flag = 0; switch (i) { @@ -924,7 +924,7 @@ static void revertSettings(WMButton * button, InspectorPanel * panel) } WMSetButtonSelected(panel->attrChk[i], flag); } - for (i = 0; i < 12; i++) { + for (i = 0; i < (sizeof(panel->moreChk) / sizeof(panel->moreChk[0])); i++) { int flag = 0; switch (i) { @@ -970,7 +970,7 @@ static void revertSettings(WMButton * button, InspectorPanel * panel) WMSetButtonSelected(panel->moreChk[i], flag); } if (panel->appFrm && wapp) { - for (i = 0; i < 3; i++) { + for (i = 0; i < (sizeof(panel->appChk) / sizeof(panel->appChk[0])); i++) { int flag = 0; switch (i) { @@ -1252,7 +1252,7 @@ static InspectorPanel *createInspectorForWindow(WWindow * wwin, int xpos, int yp WMMoveWidget(panel->attrFrm, 15, 45); WMResizeWidget(panel->attrFrm, frame_width, 250); - for (i = 0; i < 11; i++) { + for (i = 0; i < (sizeof(panel->attrChk) / sizeof(panel->attrChk[0])); i++) { char *caption = NULL; int flag = 0; char *descr = NULL; @@ -1334,13 +1334,7 @@ static InspectorPanel *createInspectorForWindow(WWindow * wwin, int xpos, int yp WMMoveWidget(panel->moreFrm, 15, 45); WMResizeWidget(panel->moreFrm, frame_width, 265); - for (i = 0; -#ifdef XKB_BUTTON_HINT - i < 12; -#else - i < 11; -#endif - i++) { + for (i = 0; i < (sizeof(panel->moreChk) / sizeof(panel->moreChk[0])); i++) { char *caption = NULL; int flag = 0; char *descr = NULL; @@ -1506,7 +1500,7 @@ static InspectorPanel *createInspectorForWindow(WWindow * wwin, int xpos, int yp WMMoveWidget(panel->appFrm, 15, 50); WMResizeWidget(panel->appFrm, frame_width, 240); - for (i = 0; i < 3; i++) { + for (i = 0; i < (sizeof(panel->appChk) / sizeof(panel->appChk[0])); i++) { char *caption = NULL; int flag = 0; char *descr = NULL;