(svn r6674) -Fix r6631: two loops had incorrect behaviour (out of bound access in widget arrays)
authorglx
Fri, 06 Oct 2006 23:17:04 +0000
changeset 4760 eec35189bfeb
parent 4759 4cc941b61b07
child 4761 40beac850798
(svn r6674) -Fix r6631: two loops had incorrect behaviour (out of bound access in widget arrays)
graph_gui.c
--- a/graph_gui.c	Fri Oct 06 22:08:37 2006 +0000
+++ b/graph_gui.c	Fri Oct 06 23:17:04 2006 +0000
@@ -224,10 +224,9 @@
 
 	switch (e->event) {
 	case WE_CREATE: {
-		uint include_bits = ~_legend_excludebits;
 		int i;
-		for (i = 0; include_bits != 0; i++, include_bits >>= 1) {
-			if (HASBIT(include_bits, 0)) LowerWindowWidget(w, i + 3);
+		for (i = 0; w->widget[i + 3].type != WWT_LAST; i++) {
+			if (!HASBIT(_legend_excludebits, i)) LowerWindowWidget(w, i + 3);
 		}
 		break;
 	}
@@ -706,10 +705,9 @@
 {
 	switch (e->event) {
 	case WE_CREATE: {
-		uint to_select = ~_legend_cargobits;
 		int i;
-		for (i = 0; to_select != 0; i++, to_select >>= 1) {
-			if (HASBIT(to_select, 0)) LowerWindowWidget(w, i + 3);
+		for (i = 0; w->widget[i + 3].type != WWT_LAST; i++) {
+			if (!HASBIT(_legend_cargobits, i)) LowerWindowWidget(w, i + 3);
 		}
 		break;
 	}