diff options
-rw-r--r-- | src/core/math_func.hpp | 1 | ||||
-rw-r--r-- | src/rail_gui.cpp | 2 |
2 files changed, 2 insertions, 1 deletions
diff --git a/src/core/math_func.hpp b/src/core/math_func.hpp index 48690ec58..e0b9dbc89 100644 --- a/src/core/math_func.hpp +++ b/src/core/math_func.hpp @@ -150,6 +150,7 @@ static FORCEINLINE T *AlignPtr(T *x, uint n) template <typename T> static FORCEINLINE T Clamp(const T a, const T min, const T max) { + assert(min <= max); if (a <= min) return min; if (a >= max) return max; return a; diff --git a/src/rail_gui.cpp b/src/rail_gui.cpp index 388a5876c..99877fd3c 100644 --- a/src/rail_gui.cpp +++ b/src/rail_gui.cpp @@ -1017,7 +1017,7 @@ public: this->vscroll.SetCount(_railstation.station_count); this->vscroll.SetCapacity(GB(this->GetWidget<NWidgetCore>(BRSW_NEWST_LIST)->widget_data, MAT_ROW_START, MAT_ROW_BITS)); - this->vscroll.SetPosition(Clamp(_railstation.station_type - 2, 0, this->vscroll.GetCount() - this->vscroll.GetCapacity())); + this->vscroll.SetPosition(Clamp(_railstation.station_type - 2, 0, max(this->vscroll.GetCount() - this->vscroll.GetCapacity(), 0))); } else { /* New stations are not available, so ensure the default station * type is 'selected'. */ |