(svn r7352) -Codechange: add widget_count parameter to the window.
authorrubidium
Mon, 04 Dec 2006 13:36:27 +0000
changeset 5232 d099cc0d7961
parent 5231 ac9fcb5cc5f4
child 5233 b2d0c1be98ad
(svn r7352) -Codechange: add widget_count parameter to the window.
-Codechange: check whether widget indices are valid for all the (Set|Is)WindowWidget(Disabled|Lowered|Hidden) and related functions.
window.c
window.h
--- a/window.c	Mon Dec 04 13:20:14 2006 +0000
+++ b/window.c	Mon Dec 04 13:36:27 2006 +0000
@@ -316,6 +316,7 @@
 	SetWindowDirty(w);
 	free(w->widget);
 	w->widget = NULL;
+	w->widget_count = 0;
 
 	/* Find the window in the z-array, and effectively remove it
 	 * by moving all windows after it one to the left */
@@ -519,8 +520,10 @@
 
 		w->widget = realloc(w->widget, sizeof(*w->widget) * index);
 		memcpy(w->widget, widget, sizeof(*w->widget) * index);
+		w->widget_count = index - 1;
 	} else {
 		w->widget = NULL;
+		w->widget_count = 0;
 	}
 }
 
@@ -877,6 +880,7 @@
 	FOR_ALL_WINDOWS(wz) {
 		free((*wz)->widget);
 		(*wz)->widget = NULL;
+		(*wz)->widget_count = 0;
 	}
 }
 
--- a/window.h	Mon Dec 04 13:20:14 2006 +0000
+++ b/window.h	Mon Dec 04 13:36:27 2006 +0000
@@ -331,6 +331,7 @@
 	ViewPort *viewport;
 	const Widget *original_widget;
 	Widget *widget;
+	uint widget_count;
 	uint32 desc_flags;
 
 	WindowMessage message;
@@ -640,6 +641,7 @@
  */
 static inline void SetWindowWidgetDisabledState(Window *w, byte widget_index, bool disab_stat)
 {
+	assert(widget_index < w->widget_count);
 	SB(w->widget[widget_index].display_flags, WIDG_DISABLED, 1, !!disab_stat);
 }
 
@@ -682,6 +684,7 @@
  */
 static inline bool IsWindowWidgetDisabled(Window *w, byte widget_index)
 {
+	assert(widget_index < w->widget_count);
 	return IsWidgetDisabled(&w->widget[widget_index]);
 }
 
@@ -695,6 +698,7 @@
  */
 static inline void SetWindowWidgetHiddenState(Window *w, byte widget_index, bool hidden_stat)
 {
+	assert(widget_index < w->widget_count);
 	SB(w->widget[widget_index].display_flags, WIDG_HIDDEN, 1, !!hidden_stat);
 }
 
@@ -737,6 +741,7 @@
  */
 static inline bool IsWindowWidgetHidden(Window *w, byte widget_index)
 {
+	assert(widget_index < w->widget_count);
 	return IsWidgetHidden(&w->widget[widget_index]);
 }
 
@@ -748,6 +753,7 @@
  */
 static inline void SetWindowWidgetLoweredState(Window *w, byte widget_index, bool lowered_stat)
 {
+	assert(widget_index < w->widget_count);
 	SB(w->widget[widget_index].display_flags, WIDG_LOWERED, 1, !!lowered_stat);
 }
 
@@ -758,6 +764,7 @@
  */
 static inline void ToggleWidgetLoweredState(Window *w, byte widget_index)
 {
+	assert(widget_index < w->widget_count);
 	TOGGLEBIT(w->widget[widget_index].display_flags, WIDG_LOWERED);
 }
 
@@ -789,6 +796,7 @@
  */
 static inline bool IsWindowWidgetLowered(Window *w, byte widget_index)
 {
+	assert(widget_index < w->widget_count);
 	return HASBIT(w->widget[widget_index].display_flags, WIDG_LOWERED);
 }