1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-30 16:24:05 +03:00

MDEV-33161 Function pointer signature mismatch in LF_HASH

In cmake -DWITH_UBSAN=ON builds with clang but not with GCC,
-fsanitize=undefined will flag several runtime errors on
function pointer mismatch related to the lock-free hash table LF_HASH.

Let us use matching function signatures and remove function pointer
casts in order to avoid potential bugs due to undefined behaviour.

These errors could be caught at compilation time by
-Wcast-function-type-strict, which is available starting with clang-16,
but not available in any version of GCC as of now. The old GCC flag
-Wcast-function-type is enabled as part of -Wextra, but it specifically
does not catch these errors.

Reviewed by: Vladislav Vaintroub
This commit is contained in:
Marko Mäkelä
2024-06-10 12:35:33 +03:00
parent 246c0b3a35
commit a2bd936c52
12 changed files with 137 additions and 131 deletions

View File

@ -252,9 +252,10 @@ public:
};
static my_bool list_open_tables_callback(TDC_element *element,
list_open_tables_arg *arg)
static my_bool list_open_tables_callback(void *el, void *a)
{
TDC_element *element= static_cast<TDC_element*>(el);
list_open_tables_arg *arg= static_cast<list_open_tables_arg*>(a);
const Lex_ident_db
db= Lex_ident_db(Lex_cstring_strlen((const char*) element->m_key));
const char *table_name= db.str + db.length + 1;
@ -302,8 +303,7 @@ OPEN_TABLE_LIST *list_open_tables(THD *thd,
DBUG_ENTER("list_open_tables");
list_open_tables_arg argument(thd, db, wild);
if (tdc_iterate(thd, (my_hash_walk_action) list_open_tables_callback,
&argument, true))
if (tdc_iterate(thd, list_open_tables_callback, &argument, true))
DBUG_RETURN(0);
DBUG_RETURN(argument.open_list);
@ -462,9 +462,10 @@ struct tc_collect_arg
flush_tables_type flush_type;
};
static my_bool tc_collect_used_shares(TDC_element *element,
tc_collect_arg *arg)
static my_bool tc_collect_used_shares(void *el, void *a)
{
TDC_element *element= static_cast<TDC_element*>(el);
tc_collect_arg *arg= static_cast<tc_collect_arg*>(a);
my_bool result= FALSE;
DYNAMIC_ARRAY *shares= &arg->shares;
@ -573,8 +574,7 @@ bool flush_tables(THD *thd, flush_tables_type flag)
my_init_dynamic_array(PSI_INSTRUMENT_ME, &collect_arg.shares,
sizeof(TABLE_SHARE*), 100, 100, MYF(0));
collect_arg.flush_type= flag;
if (tdc_iterate(thd, (my_hash_walk_action) tc_collect_used_shares,
&collect_arg, true))
if (tdc_iterate(thd, tc_collect_used_shares, &collect_arg, true))
{
/* Release already collected shares */
for (uint i= 0 ; i < collect_arg.shares.elements ; i++)