From 904ecb1d366c470659bb3a9c1cf30793f456c4d9 Mon Sep 17 00:00:00 2001 From: A Thousand Ships <96648715+AThousandShips@users.noreply.github.com> Date: Tue, 21 Nov 2023 17:20:52 +0100 Subject: [PATCH] [Core] Prevent copying of `SelfList` and `SelfList::List` Copying of these types is unsafe and should be detected Also removed unnecessary constructors for `TileMap` `DebugQuadrant` and `RenderingQuadrant` which used copying of `SelfList::List` --- core/templates/self_list.h | 6 ++++++ scene/2d/tile_map_layer.h | 16 ---------------- 2 files changed, 6 insertions(+), 16 deletions(-) diff --git a/core/templates/self_list.h b/core/templates/self_list.h index fdf91beacca..afa0501c75c 100644 --- a/core/templates/self_list.h +++ b/core/templates/self_list.h @@ -159,6 +159,9 @@ public: _FORCE_INLINE_ SelfList *first() { return _first; } _FORCE_INLINE_ const SelfList *first() const { return _first; } + // Forbid copying, which has broken behavior. + void operator=(const List &) = delete; + _FORCE_INLINE_ List() {} _FORCE_INLINE_ ~List() { // A self list must be empty on destruction. @@ -185,6 +188,9 @@ public: _FORCE_INLINE_ const SelfList *prev() const { return _prev; } _FORCE_INLINE_ T *self() const { return _self; } + // Forbid copying, which has broken behavior. + void operator=(const SelfList &) = delete; + _FORCE_INLINE_ SelfList(T *p_self) { _self = p_self; } diff --git a/scene/2d/tile_map_layer.h b/scene/2d/tile_map_layer.h index 8db34d8aae6..3125fcb488d 100644 --- a/scene/2d/tile_map_layer.h +++ b/scene/2d/tile_map_layer.h @@ -173,14 +173,6 @@ public: SelfList dirty_quadrant_list_element; - // For those, copy everything but SelfList elements. - DebugQuadrant(const DebugQuadrant &p_other) : - dirty_quadrant_list_element(this) { - quadrant_coords = p_other.quadrant_coords; - cells = p_other.cells; - canvas_item = p_other.canvas_item; - } - DebugQuadrant() : dirty_quadrant_list_element(this) { } @@ -213,14 +205,6 @@ public: SelfList dirty_quadrant_list_element; - // For those, copy everything but SelfList elements. - RenderingQuadrant(const RenderingQuadrant &p_other) : - dirty_quadrant_list_element(this) { - quadrant_coords = p_other.quadrant_coords; - cells = p_other.cells; - canvas_items = p_other.canvas_items; - } - RenderingQuadrant() : dirty_quadrant_list_element(this) { }