From bb50cbb7728ccdd0641399777033e1e9d4eca61a Mon Sep 17 00:00:00 2001 From: Peter Nelson Date: Wed, 1 Nov 2023 18:44:23 +0000 Subject: [PATCH] Codechange: Assign/StoreSizePosition x/y can be negative. (#11416) AssignSizePosition is used with negative values when an NWidgetMatrix is scrolled, but they were passed as unsigned and then stored as signed. Widget pos_x/pos_y were already made signed. --- src/network/network_gui.cpp | 2 +- src/newgrf_gui.cpp | 2 +- src/smallmap_gui.cpp | 2 +- src/toolbar_gui.cpp | 2 +- src/widget.cpp | 16 ++++++++-------- src/widget_type.h | 20 ++++++++++---------- 6 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/network/network_gui.cpp b/src/network/network_gui.cpp index 97ee785cb9..4d9d6b464a 100644 --- a/src/network/network_gui.cpp +++ b/src/network/network_gui.cpp @@ -129,7 +129,7 @@ public: this->smallest_x = this->head->smallest_x + this->tail->smallest_x; // First and last are always shown, rest not } - void AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl) override + void AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool rtl) override { assert(given_width >= this->smallest_x && given_height >= this->smallest_y); diff --git a/src/newgrf_gui.cpp b/src/newgrf_gui.cpp index 036914cfe1..04929fb2b8 100644 --- a/src/newgrf_gui.cpp +++ b/src/newgrf_gui.cpp @@ -1667,7 +1667,7 @@ public: this->smallest_y = ComputeMaxSize(min_acs_height, this->smallest_y + this->resize_y - 1, this->resize_y); } - void AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl) override + void AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool rtl) override { this->StoreSizePosition(sizing, x, y, given_width, given_height); diff --git a/src/smallmap_gui.cpp b/src/smallmap_gui.cpp index 7ff1c62dfe..09f73b6d32 100644 --- a/src/smallmap_gui.cpp +++ b/src/smallmap_gui.cpp @@ -1740,7 +1740,7 @@ public: this->resize_y = std::min(display->resize_y, bar->resize_y); } - void AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl) override + void AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool rtl) override { this->pos_x = x; this->pos_y = y; diff --git a/src/toolbar_gui.cpp b/src/toolbar_gui.cpp index 2fa08a805f..5f3f279acf 100644 --- a/src/toolbar_gui.cpp +++ b/src/toolbar_gui.cpp @@ -1424,7 +1424,7 @@ public: _toolbar_width = nbuttons * this->smallest_x; } - void AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl) override + void AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool rtl) override { assert(given_width >= this->smallest_x && given_height >= this->smallest_y); diff --git a/src/widget.cpp b/src/widget.cpp index ebeefc55aa..fa91b1f66d 100644 --- a/src/widget.cpp +++ b/src/widget.cpp @@ -1008,7 +1008,7 @@ NWidgetBase::NWidgetBase(WidgetType tp) : ZeroedMemoryAllocator() */ /** - * @fn void NWidgetBase::AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl) + * @fn void NWidgetBase::AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool rtl) * Assign size and position to the widget. * @param sizing Type of resizing to perform. * @param x Horizontal offset of the widget relative to the left edge of the window. @@ -1163,7 +1163,7 @@ bool NWidgetResizeBase::UpdateVerticalSize(uint min_y) return true; } -void NWidgetResizeBase::AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool) +void NWidgetResizeBase::AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool) { this->StoreSizePosition(sizing, x, y, given_width, given_height); } @@ -1400,7 +1400,7 @@ void NWidgetStacked::SetupSmallestSize(Window *w, bool init_array) } } -void NWidgetStacked::AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl) +void NWidgetStacked::AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool rtl) { assert(given_width >= this->smallest_x && given_height >= this->smallest_y); this->StoreSizePosition(sizing, x, y, given_width, given_height); @@ -1570,7 +1570,7 @@ void NWidgetHorizontal::SetupSmallestSize(Window *w, bool init_array) this->pip_pre = this->pip_inter = this->pip_post = 0; } -void NWidgetHorizontal::AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl) +void NWidgetHorizontal::AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool rtl) { assert(given_width >= this->smallest_x && given_height >= this->smallest_y); @@ -1678,7 +1678,7 @@ NWidgetHorizontalLTR::NWidgetHorizontalLTR(NWidContainerFlags flags) : NWidgetHo this->type = NWID_HORIZONTAL_LTR; } -void NWidgetHorizontalLTR::AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool) +void NWidgetHorizontalLTR::AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool) { NWidgetHorizontal::AssignSizePosition(sizing, x, y, given_width, given_height, false); } @@ -1755,7 +1755,7 @@ void NWidgetVertical::SetupSmallestSize(Window *w, bool init_array) this->pip_pre = this->pip_inter = this->pip_post = 0; } -void NWidgetVertical::AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl) +void NWidgetVertical::AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool rtl) { assert(given_width >= this->smallest_x && given_height >= this->smallest_y); @@ -1981,7 +1981,7 @@ void NWidgetMatrix::SetupSmallestSize(Window *w, bool init_array) this->resize_y = resize.height; } -void NWidgetMatrix::AssignSizePosition(SizingType, uint x, uint y, uint given_width, uint given_height, bool) +void NWidgetMatrix::AssignSizePosition(SizingType, int x, int y, uint given_width, uint given_height, bool) { assert(given_width >= this->smallest_x && given_height >= this->smallest_y); @@ -2249,7 +2249,7 @@ void NWidgetBackground::SetupSmallestSize(Window *w, bool init_array) } } -void NWidgetBackground::AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl) +void NWidgetBackground::AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool rtl) { this->StoreSizePosition(sizing, x, y, given_width, given_height); diff --git a/src/widget_type.h b/src/widget_type.h index ae71ca11e6..baa9623053 100644 --- a/src/widget_type.h +++ b/src/widget_type.h @@ -127,7 +127,7 @@ public: virtual void AdjustPaddingForZoom(); virtual void SetupSmallestSize(Window *w, bool init_array) = 0; - virtual void AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl) = 0; + virtual void AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool rtl) = 0; virtual void FillNestedArray(NWidgetBase **array, uint length) = 0; @@ -204,7 +204,7 @@ public: RectPadding uz_padding; ///< Unscaled padding, for resize calculation. protected: - inline void StoreSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height); + inline void StoreSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height); }; /** @@ -233,7 +233,7 @@ inline uint NWidgetBase::GetVerticalStepSize(SizingType sizing) const * @param given_width Width allocated to the widget. * @param given_height Height allocated to the widget. */ -inline void NWidgetBase::StoreSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height) +inline void NWidgetBase::StoreSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height) { this->pos_x = x; this->pos_y = y; @@ -263,7 +263,7 @@ public: bool UpdateVerticalSize(uint min_y); - void AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl) override; + void AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool rtl) override; uint min_x; ///< Minimal horizontal size of only this widget. uint min_y; ///< Minimal vertical size of only this widget. @@ -452,7 +452,7 @@ public: void AdjustPaddingForZoom() override; void SetupSmallestSize(Window *w, bool init_array) override; - void AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl) override; + void AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool rtl) override; void FillNestedArray(NWidgetBase **array, uint length) override; void Draw(const Window *w) override; @@ -503,7 +503,7 @@ public: NWidgetHorizontal(NWidContainerFlags flags = NC_NONE); void SetupSmallestSize(Window *w, bool init_array) override; - void AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl) override; + void AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool rtl) override; }; /** @@ -514,7 +514,7 @@ class NWidgetHorizontalLTR : public NWidgetHorizontal { public: NWidgetHorizontalLTR(NWidContainerFlags flags = NC_NONE); - void AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl) override; + void AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool rtl) override; }; /** @@ -526,7 +526,7 @@ public: NWidgetVertical(NWidContainerFlags flags = NC_NONE); void SetupSmallestSize(Window *w, bool init_array) override; - void AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl) override; + void AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool rtl) override; }; /** @@ -548,7 +548,7 @@ public: void SetScrollbar(Scrollbar *sb); void SetupSmallestSize(Window *w, bool init_array) override; - void AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl) override; + void AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool rtl) override; void FillNestedArray(NWidgetBase **array, uint length) override; NWidgetCore *GetWidgetFromPos(int x, int y) override; @@ -599,7 +599,7 @@ public: void AdjustPaddingForZoom() override; void SetupSmallestSize(Window *w, bool init_array) override; - void AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl) override; + void AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool rtl) override; void FillNestedArray(NWidgetBase **array, uint length) override;