From 519cb3e103ef1590fee45c02cd0df5af5106eea6 Mon Sep 17 00:00:00 2001 From: rubidium Date: Tue, 26 Nov 2013 13:21:25 +0000 Subject: [PATCH] (svn r26121) -Codechange: add some asserts after dynamic casts to show they shouldn't return NULL ever --- src/smallmap_gui.cpp | 1 + src/widget.cpp | 10 ++++++++-- src/widgets/dropdown.cpp | 1 + 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/smallmap_gui.cpp b/src/smallmap_gui.cpp index 85a1236264..99097c5719 100644 --- a/src/smallmap_gui.cpp +++ b/src/smallmap_gui.cpp @@ -1644,6 +1644,7 @@ public: bar->SetupSmallestSize(w, init_array); this->smallmap_window = dynamic_cast(w); + assert(this->smallmap_window != NULL); this->smallest_x = max(display->smallest_x, bar->smallest_x + smallmap_window->GetMinLegendWidth()); this->smallest_y = display->smallest_y + max(bar->smallest_y, smallmap_window->GetLegendHeight(smallmap_window->min_number_of_columns)); this->fill_x = max(display->fill_x, bar->fill_x); diff --git a/src/widget.cpp b/src/widget.cpp index 839ee98ce3..6e73fd4491 100644 --- a/src/widget.cpp +++ b/src/widget.cpp @@ -147,7 +147,9 @@ void ScrollbarClickHandler(Window *w, NWidgetCore *nw, int x, int y) mi = nw->pos_y; ma = nw->pos_y + nw->current_y; } - ScrollbarClickPositioning(w, dynamic_cast(nw), x, y, mi, ma); + NWidgetScrollbar *scrollbar = dynamic_cast(nw); + assert(scrollbar != NULL); + ScrollbarClickPositioning(w, scrollbar, x, y, mi, ma); } /** @@ -1526,7 +1528,9 @@ void NWidgetMatrix::SetupSmallestSize(Window *w, bool init_array) } /* Reset the widget number. */ - SB(dynamic_cast(this->head)->index, 16, 16, 0); + NWidgetCore *nw = dynamic_cast(this->head); + assert(nw != NULL); + SB(nw->index, 16, 16, 0); this->head->SetupSmallestSize(w, init_array); Dimension padding = {this->pip_pre + this->pip_post, this->pip_pre + this->pip_post}; @@ -1595,6 +1599,7 @@ NWidgetCore *NWidgetMatrix::GetWidgetFromPos(int x, int y) if (sub_wid >= this->count) return NULL; NWidgetCore *child = dynamic_cast(this->head); + assert(child != NULL); child->AssignSizePosition(ST_RESIZE, this->pos_x + (rtl ? this->pip_post - widget_col * this->widget_w : this->pip_pre + widget_col * this->widget_w) + base_offs_x, this->pos_y + this->pip_pre + widget_row * this->widget_h + base_offs_y, @@ -1619,6 +1624,7 @@ NWidgetCore *NWidgetMatrix::GetWidgetFromPos(int x, int y) /* Get the appropriate offsets so we can draw the right widgets. */ NWidgetCore *child = dynamic_cast(this->head); + assert(child != NULL); int start_x, start_y, base_offs_x, base_offs_y; this->GetScrollOffsets(start_x, start_y, base_offs_x, base_offs_y); diff --git a/src/widgets/dropdown.cpp b/src/widgets/dropdown.cpp index 4005148224..7da533a745 100644 --- a/src/widgets/dropdown.cpp +++ b/src/widgets/dropdown.cpp @@ -475,6 +475,7 @@ int HideDropDownMenu(Window *pw) if (w->window_class != WC_DROPDOWN_MENU) continue; DropdownWindow *dw = dynamic_cast(w); + assert(dw != NULL); if (pw->window_class == dw->parent_wnd_class && pw->window_number == dw->parent_wnd_num) { int parent_button = dw->parent_button;