From 22cd51e950bedc51a8565e5318f692f10a156d52 Mon Sep 17 00:00:00 2001 From: Xingyu Yang Date: Mon, 29 Jul 2024 15:06:34 +0800 Subject: [PATCH] [bugfix] issue#1432 Assignment from a local empty SQL_I_list got an illegal object Problem: ======== SQL_I_list uses member field 'next' to track the pointer field to the next object. It is initialized as the address of member field 'first', which is only valid with the list object constructed with regular constructors. However, assignment operators and move constructor of SQL_I_list used trivial implementations, as of 8.0.14, by Bug#28509897 GCC 9 WARNINGS. As a result, the lhs got an illegal 'next' field. Solution: ========= Supply customized move constructor and operator= functions. MR!1859, reviewed by kenkkchen. --- sql/sql_list.h | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/sql/sql_list.h b/sql/sql_list.h index ed9f4128c78..ec05d674fd5 100644 --- a/sql/sql_list.h +++ b/sql/sql_list.h @@ -57,7 +57,12 @@ class SQL_I_List { first(tmp.first), next(elements ? tmp.next : &first) {} - SQL_I_List(SQL_I_List &&) = default; + SQL_I_List(SQL_I_List &&tmp) + : elements(tmp.elements), + first(tmp.first), + next(elements ? tmp.next : &first) { + tmp.clear(); + } inline void clear() { elements = 0; @@ -94,8 +99,26 @@ class SQL_I_List { inline uint size() const { return elements; } - SQL_I_List &operator=(SQL_I_List &) = default; - SQL_I_List &operator=(SQL_I_List &&) = default; + SQL_I_List &operator=(const SQL_I_List &tmp) { + if (this == &tmp) { + return *this; + } + elements = tmp.elements; + first = tmp.first; + next = elements ? tmp.next : &first; + return *this; + } + + SQL_I_List &operator=(SQL_I_List &&tmp) { + if (this == &tmp) { + return *this; + } + elements = tmp.elements; + first = tmp.first; + next = elements ? tmp.next : &first; + tmp.clear(); + return *this; + } }; /* -- 2.39.3