Skip to content

Commit

Permalink
MDEV-33158: UBSAN - plugin.cc partial move to C++ casts
Browse files Browse the repository at this point in the history
There were too many C casts rather than C++ casts here.

Started a partial conversion covering within-file scoped
changes.

Suggested by Brandon Nesterenko
  • Loading branch information
grooverdan committed Jan 12, 2025
1 parent cdaeb09 commit e4d647d
Showing 1 changed file with 23 additions and 23 deletions.
46 changes: 23 additions & 23 deletions sql/sql_plugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3186,14 +3186,14 @@ void sync_dynamic_session_variables(THD* thd, bool global_lock)
If required, will sync with global variables if the requested variable
has not yet been allocated in the current thread.
*/
static uchar *intern_sys_var_ptr(THD* thd, int offset, bool global_lock)
static void *intern_sys_var_ptr(THD* thd, int offset, bool global_lock)
{
DBUG_ENTER("intern_sys_var_ptr");
DBUG_ASSERT(offset >= 0);
DBUG_ASSERT((uint)offset <= global_system_variables.dynamic_variables_head);

if (!thd)
DBUG_RETURN((uchar*) global_system_variables.dynamic_variables_ptr + offset);
DBUG_RETURN(global_system_variables.dynamic_variables_ptr + offset);

/*
dynamic_variables_head points to the largest valid offset
Expand All @@ -3205,7 +3205,7 @@ static uchar *intern_sys_var_ptr(THD* thd, int offset, bool global_lock)
sync_dynamic_session_variables(thd, global_lock);
mysql_prlock_unlock(&LOCK_system_variables_hash);
}
DBUG_RETURN((uchar*)thd->variables.dynamic_variables_ptr + offset);
DBUG_RETURN(thd->variables.dynamic_variables_ptr + offset);
}


Expand All @@ -3219,47 +3219,47 @@ static uchar *intern_sys_var_ptr(THD* thd, int offset, bool global_lock)

static char *mysql_sys_var_char(THD* thd, int offset)
{
return (char *) intern_sys_var_ptr(thd, offset, true);
return static_cast<char*>(intern_sys_var_ptr(thd, offset, true));
}

static int *mysql_sys_var_int(THD* thd, int offset)
{
return (int *) intern_sys_var_ptr(thd, offset, true);
return static_cast<int*>(intern_sys_var_ptr(thd, offset, true));
}

static unsigned int *mysql_sys_var_uint(THD* thd, int offset)
{
return (unsigned int *) intern_sys_var_ptr(thd, offset, true);
return static_cast<unsigned int*>(intern_sys_var_ptr(thd, offset, true));
}

static long *mysql_sys_var_long(THD* thd, int offset)
{
return (long *) intern_sys_var_ptr(thd, offset, true);
return static_cast<long*>(intern_sys_var_ptr(thd, offset, true));
}

static unsigned long *mysql_sys_var_ulong(THD* thd, int offset)
{
return (unsigned long *) intern_sys_var_ptr(thd, offset, true);
return static_cast<unsigned long*>(intern_sys_var_ptr(thd, offset, true));
}

static long long *mysql_sys_var_longlong(THD* thd, int offset)
{
return (long long *) intern_sys_var_ptr(thd, offset, true);
return static_cast<long long*>(intern_sys_var_ptr(thd, offset, true));
}

static unsigned long long *mysql_sys_var_ulonglong(THD* thd, int offset)
{
return (unsigned long long *) intern_sys_var_ptr(thd, offset, true);
return static_cast<unsigned long long*>(intern_sys_var_ptr(thd, offset, true));
}

static char **mysql_sys_var_str(THD* thd, int offset)
{
return (char **) intern_sys_var_ptr(thd, offset, true);
return static_cast<char**>(intern_sys_var_ptr(thd, offset, true));
}

static double *mysql_sys_var_double(THD* thd, int offset)
{
return (double *) intern_sys_var_ptr(thd, offset, true);
return static_cast<double*>(intern_sys_var_ptr(thd, offset, true));
}

void plugin_thdvar_init(THD *thd)
Expand Down Expand Up @@ -3520,7 +3520,7 @@ uchar* sys_var_pluginvar::real_value_ptr(THD *thd, enum_var_type type) const
if (type == OPT_GLOBAL)
thd= NULL;

return intern_sys_var_ptr(thd, *(int*) (plugin_var+1), false);
return (uchar*) intern_sys_var_ptr(thd, *(int*) (plugin_var+1), false);
}
return *(uchar**) (plugin_var+1);
}
Expand All @@ -3529,8 +3529,8 @@ uchar* sys_var_pluginvar::real_value_ptr(THD *thd, enum_var_type type) const
bool sys_var_pluginvar::session_is_default(THD *thd)
{
uchar *value= plugin_var->flags & PLUGIN_VAR_THDLOCAL
? intern_sys_var_ptr(thd, *(int*) (plugin_var+1), true)
: *(uchar**) (plugin_var+1);
? static_cast<uchar*>(intern_sys_var_ptr(thd, *(int*) (plugin_var+1), true))
: *reinterpret_cast<uchar**>(plugin_var+1);

real_value_ptr(thd, OPT_SESSION);

Expand Down Expand Up @@ -3772,27 +3772,27 @@ void plugin_opt_set_limits(struct my_option *options,
break;
case PLUGIN_VAR_ENUM | PLUGIN_VAR_THDLOCAL:
options->var_type= GET_ENUM;
options->typelib= ((thdvar_enum_t*) opt)->typelib;
options->def_value= ((thdvar_enum_t*) opt)->def_val;
options->typelib= reinterpret_cast<const thdvar_enum_t*>(opt)->typelib;
options->def_value= reinterpret_cast<const thdvar_enum_t*>(opt)->def_val;
options->min_value= options->block_size= 0;
options->max_value= options->typelib->count - 1;
break;
case PLUGIN_VAR_SET | PLUGIN_VAR_THDLOCAL:
options->var_type= GET_SET;
options->typelib= ((thdvar_set_t*) opt)->typelib;
options->def_value= ((thdvar_set_t*) opt)->def_val;
options->typelib= reinterpret_cast<const thdvar_set_t*>(opt)->typelib;
options->def_value= reinterpret_cast<const thdvar_set_t*>(opt)->def_val;
options->min_value= options->block_size= 0;
options->max_value= (1ULL << options->typelib->count) - 1;
break;
case PLUGIN_VAR_BOOL | PLUGIN_VAR_THDLOCAL:
options->var_type= GET_BOOL;
options->def_value= ((thdvar_bool_t*) opt)->def_val;
options->def_value= reinterpret_cast<const thdvar_bool_t*>(opt)->def_val;
options->typelib= &bool_typelib;
break;
case PLUGIN_VAR_STR | PLUGIN_VAR_THDLOCAL:
options->var_type= ((opt->flags & PLUGIN_VAR_MEMALLOC) ?
GET_STR_ALLOC : GET_STR);
options->def_value= (intptr) ((thdvar_str_t*) opt)->def_val;
options->def_value= reinterpret_cast<intptr_t>(reinterpret_cast<const thdvar_str_t*>(opt)->def_val);
break;
default:
DBUG_ASSERT(0);
Expand Down Expand Up @@ -3831,7 +3831,7 @@ static int construct_options(MEM_ROOT *mem_root, struct st_plugin_int *tmp,
size_t plugin_name_len= strlen(plugin_name);
size_t optnamelen;
const int max_comment_len= 255;
char *comment= (char *) alloc_root(mem_root, max_comment_len + 1);
char *comment= static_cast<char*>(alloc_root(mem_root, max_comment_len + 1));
char *optname;

int index= 0, UNINIT_VAR(offset);
Expand All @@ -3843,7 +3843,7 @@ static int construct_options(MEM_ROOT *mem_root, struct st_plugin_int *tmp,

DBUG_ENTER("construct_options");

plugin_name_ptr= (char*) alloc_root(mem_root, plugin_name_len + 1);
plugin_name_ptr= static_cast<char*>(alloc_root(mem_root, plugin_name_len + 1));
safe_strcpy(plugin_name_ptr, plugin_name_len + 1, plugin_name);
my_casedn_str(&my_charset_latin1, plugin_name_ptr);
convert_underscore_to_dash(plugin_name_ptr, plugin_name_len);
Expand Down

0 comments on commit e4d647d

Please sign in to comment.