From 35feea4423adb3dbc5851f5a76a2e5697ca685e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tin=20=C5=A0vagelj?= Date: Thu, 25 Apr 2024 20:22:33 +0200 Subject: [PATCH] Ensure component access always returns wanted type MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This should help avoid bad pointer reinterpretation. Signed-off-by: Tin Å vagelj --- src/geometry.h | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/src/geometry.h b/src/geometry.h index 91295d6c5..f289dfb30 100644 --- a/src/geometry.h +++ b/src/geometry.h @@ -52,10 +52,18 @@ struct point { /// @brief Point x component /// @return x value of this point - inline T x() const { return value.x(); } + template ::value>> + inline R x() const { + return reinterpret_cast(this->value.x()); + } /// @brief Point y component /// @return y value of this point - inline T y() const { return value.y(); } + template ::value>> + inline R y() const { + return reinterpret_cast(this->value.y()); + } template ::value>> @@ -148,16 +156,32 @@ struct rect { /// @brief Rectangle x position /// @return x position of this rectangle - inline T x() const { return this->pos.x(); } + template ::value>> + inline R x() const { + return reinterpret_cast(this->pos.x()); + } /// @brief Rectangle y position /// @return y position of this rectangle - inline T y() const { return this->pos.y(); } + template ::value>> + inline R y() const { + return reinterpret_cast(this->pos.y()); + } /// @brief Rectangle width /// @return width of this rectangle - inline T width() const { return this->size.x(); } + template ::value>> + inline R width() const { + return reinterpret_cast(this->size.x()); + } /// @brief Rectangle height /// @return height of this rectangle - inline T height() const { return this->size.y(); } + template ::value>> + inline R height() const { + return reinterpret_cast(this->size.y()); + } template ::value>>