summaryrefslogtreecommitdiff
path: root/src/window_gui.h
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2009-01-07 18:59:46 +0000
committerrubidium <rubidium@openttd.org>2009-01-07 18:59:46 +0000
commitc71862174a60e0719751afa9ca8f2ebcaa774f39 (patch)
tree27f5fec9105c3877775dd0123f12b68561def938 /src/window_gui.h
parent6bd14cf1a16f13f7b24d6eb869316a740b89b069 (diff)
downloadopenttd-c71862174a60e0719751afa9ca8f2ebcaa774f39.tar.xz
(svn r14905) -Fix (r14899): in some corner cases already freed memory could be read.
Diffstat (limited to 'src/window_gui.h')
-rw-r--r--src/window_gui.h11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/window_gui.h b/src/window_gui.h
index ea2a5f076..266bf5a80 100644
--- a/src/window_gui.h
+++ b/src/window_gui.h
@@ -203,6 +203,11 @@ public:
Window(const WindowDesc *desc, WindowNumber number = 0);
virtual ~Window();
+ /* Don't allow arrays; arrays of Windows are pointless as you need
+ * to destruct them all at the same time too, which is kinda hard. */
+ FORCEINLINE void *operator new[](size_t size) { NOT_REACHED(); }
+ /* Don't free the window directly; it corrupts the linked list when iterating */
+ FORCEINLINE void operator delete(void *ptr, size_t size) {}
uint16 flags4; ///< Window flags, @see WindowFlags
WindowClass window_class; ///< Window class
@@ -543,8 +548,10 @@ extern Window *_z_front_window;
extern Window *_z_back_window;
/** Iterate over all windows */
-#define FOR_ALL_WINDOWS_FROM_BACK(w) for (w = _z_back_window; w != NULL; w = w->z_front)
-#define FOR_ALL_WINDOWS_FROM_FRONT(w) for (w = _z_front_window; w != NULL; w = w->z_back)
+#define FOR_ALL_WINDOWS_FROM_BACK_FROM(w, start) for (w = start; w != NULL; w = w->z_front) if (w->window_class != WC_INVALID)
+#define FOR_ALL_WINDOWS_FROM_FRONT_FROM(w, start) for (w = start; w != NULL; w = w->z_back) if (w->window_class != WC_INVALID)
+#define FOR_ALL_WINDOWS_FROM_BACK(w) FOR_ALL_WINDOWS_FROM_BACK_FROM(w, _z_back_window)
+#define FOR_ALL_WINDOWS_FROM_FRONT(w) FOR_ALL_WINDOWS_FROM_FRONT_FROM(w, _z_front_window)
/**
* Disable scrolling of the main viewport when an input-window is active.