mirror of
https://github.com/MariaDB/server.git
synced 2025-07-30 16:24:05 +03:00
MDEV-34490 get_copy() and build_clone() may return an instance of an ancestor class instead of a copy/clone
The `Item` class methods `get_copy()`, `build_clone()`, and `clone_item()` face an issue where they may be defined in a descendant class (e.g., `Item_func`) but not in a further descendant (e.g., `Item_func_child`). This can lead to scenarios where `build_clone()`, when operating on an instance of `Item_func_child` with a pointer to the base class (`Item`), returns an instance of `Item_func` instead of `Item_func_child`. Since this limitation cannot be resolved at compile time, this commit introduces runtime type checks for the copy/clone operations. A debug assertion will now trigger in case of a type mismatch. `get_copy()`, `build_clone()`, and `clone_item()` are no more virtual, but virtual `do_get_copy()`, `do_build_clone()`, and `do_clone_item()` are added to the protected section of the class `Item`. Additionally, const qualifiers have been added to certain methods to enhance code reliability. Reviewer: Oleksandr Byelkin <sanja@mariadb.com>
This commit is contained in:
@ -577,7 +577,7 @@ public:
|
||||
LEX_CSTRING tmp= {Ptr, str_length};
|
||||
return tmp;
|
||||
}
|
||||
inline LEX_CSTRING *get_value(LEX_CSTRING *res)
|
||||
inline LEX_CSTRING *get_value(LEX_CSTRING *res) const
|
||||
{
|
||||
res->str= Ptr;
|
||||
res->length= str_length;
|
||||
|
Reference in New Issue
Block a user