Skip to content

Commit d6c3f70

Browse files
author
Steinar H. Gunderson
committed
Bug #26826272: REMOVE GCC 8 WARNINGS [noclose]
Remove a few nontrivial GCC 8 warnings around memcpy of non-POD objects. After this, only InnoDB warnings are left (except for one false positive that has been reported as a GCC bug). Change-Id: I45e6e8924f13e3139df7c6762b4fa6f6b72056bd
1 parent 4da9f25 commit d6c3f70

19 files changed

+56
-69
lines changed

sql/auth/sql_authentication.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1024,7 +1024,7 @@ static bool find_mpvio_user(THD *thd, MPVIO_EXT *mpvio)
10241024

10251025
static bool
10261026
read_client_connect_attrs(char **ptr, size_t *max_bytes_available,
1027-
MPVIO_EXT *mpvio)
1027+
MPVIO_EXT *mpvio MY_ATTRIBUTE((unused)))
10281028
{
10291029
size_t length, length_length;
10301030
char *ptr_save;

sql/dd_sp.cc

-2
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,6 @@ static void prepare_type_string_from_dd_param(THD *thd,
170170
// Get type in string format.
171171
TABLE table;
172172
TABLE_SHARE share;
173-
memset(&table, 0, sizeof(table));
174-
memset(&share, 0, sizeof(share));
175173
table.in_use= thd;
176174
table.s= &share;
177175

sql/handler.cc

+1-3
Original file line numberDiff line numberDiff line change
@@ -1368,7 +1368,7 @@ void ha_pre_dd_shutdown(void)
13681368
13691369
*/
13701370
void trans_register_ha(THD *thd, bool all, handlerton *ht_arg,
1371-
const ulonglong *trxid)
1371+
const ulonglong *trxid MY_ATTRIBUTE((unused)))
13721372
{
13731373
Ha_trx_info *ha_info;
13741374
Transaction_ctx *trn_ctx= thd->get_transaction();
@@ -2630,8 +2630,6 @@ int ha_delete_table(THD *thd, handlerton *table_type, const char *path,
26302630
TABLE_SHARE dummy_share;
26312631
DBUG_ENTER("ha_delete_table");
26322632

2633-
memset(&dummy_table, 0, sizeof(dummy_table));
2634-
memset(&dummy_share, 0, sizeof(dummy_share));
26352633
dummy_table.s= &dummy_share;
26362634

26372635
/* DB_TYPE_UNKNOWN is used in ALTER TABLE when renaming only .frm files */

sql/item_func.cc

-1
Original file line numberDiff line numberDiff line change
@@ -8889,7 +8889,6 @@ bool check_table_and_trigger_access(Item **args,
88898889
DBUG_RETURN(false);
88908890

88918891
TABLE_LIST table_list;
8892-
memset(&table_list, 0, sizeof (table_list));
88938892
table_list.db= schema_name_ptr->ptr();
88948893
table_list.db_length= schema_name_ptr->length();
88958894
table_list.table_name= table_name_ptr->ptr();

sql/item_strfunc.cc

-1
Original file line numberDiff line numberDiff line change
@@ -4653,7 +4653,6 @@ String *Item_func_get_dd_column_privileges::val_str(String *str)
46534653

46544654
THD *thd= current_thd;
46554655
GRANT_INFO grant_info;
4656-
memset(&grant_info, 0, sizeof (grant_info));
46574656
fill_effective_table_privileges(thd,
46584657
&grant_info,
46594658
schema_name_ptr->c_ptr_safe(),

sql/mysqld.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -8058,7 +8058,7 @@ static int mysql_init_variables()
80588058
mysqld_user= mysqld_chroot= opt_init_file= opt_bin_logname = 0;
80598059
prepared_stmt_count= 0;
80608060
mysqld_unix_port= opt_mysql_tmpdir= my_bind_addr_str= NullS;
8061-
memset(&mysql_tmpdir_list, 0, sizeof(mysql_tmpdir_list));
8061+
new (&mysql_tmpdir_list) MY_TMPDIR;
80628062
memset(&global_status_var, 0, sizeof(global_status_var));
80638063
opt_large_pages= 0;
80648064
opt_super_large_pages= 0;

sql/partition_info.cc

+5-9
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,14 @@ partition_info *partition_info::get_clone(THD *thd, bool reset /* = false */)
7373
DBUG_ENTER("partition_info::get_clone");
7474
List_iterator<partition_element> part_it(partitions);
7575
partition_element *part;
76-
partition_info *clone= new (*THR_MALLOC) partition_info();
76+
partition_info *clone= new (*THR_MALLOC) partition_info(*this);
7777
if (!clone)
7878
{
7979
mem_alloc_error(sizeof(partition_info));
8080
DBUG_RETURN(NULL);
8181
}
82-
memcpy(clone, this, sizeof(partition_info));
83-
memset(&(clone->read_partitions), 0, sizeof(clone->read_partitions));
84-
memset(&(clone->lock_partitions), 0, sizeof(clone->lock_partitions));
82+
new (&(clone->read_partitions)) MY_BITMAP;
83+
new (&(clone->lock_partitions)) MY_BITMAP;
8584
clone->bitmaps_are_initialized= FALSE;
8685
clone->partitions.empty();
8786
clone->temp_partitions.empty();
@@ -90,13 +89,12 @@ partition_info *partition_info::get_clone(THD *thd, bool reset /* = false */)
9089
{
9190
List_iterator<partition_element> subpart_it(part->subpartitions);
9291
partition_element *subpart;
93-
partition_element *part_clone= new (*THR_MALLOC) partition_element();
92+
partition_element *part_clone= new (*THR_MALLOC) partition_element(*part);
9493
if (!part_clone)
9594
{
9695
mem_alloc_error(sizeof(partition_element));
9796
DBUG_RETURN(NULL);
9897
}
99-
memcpy(part_clone, part, sizeof(partition_element));
10098

10199
/* Explicitly copy the tablespace name, use the thd->mem_root. */
102100
if (part->tablespace_name != nullptr)
@@ -125,13 +123,12 @@ partition_info *partition_info::get_clone(THD *thd, bool reset /* = false */)
125123
part_clone->subpartitions.empty();
126124
while ((subpart= (subpart_it++)))
127125
{
128-
partition_element *subpart_clone= new (*THR_MALLOC) partition_element();
126+
partition_element *subpart_clone= new (*THR_MALLOC) partition_element(*subpart);
129127
if (!subpart_clone)
130128
{
131129
mem_alloc_error(sizeof(partition_element));
132130
DBUG_RETURN(NULL);
133131
}
134-
memcpy(subpart_clone, subpart, sizeof(partition_element));
135132

136133
/* Explicitly copy the tablespace name, use the thd->mem_root. */
137134
if (subpart->tablespace_name != nullptr)
@@ -1885,7 +1882,6 @@ void partition_info::print_no_partition_found(THD *thd, TABLE *table_arg)
18851882
char *buf_ptr= (char*)&buf;
18861883
TABLE_LIST table_list;
18871884

1888-
memset(&table_list, 0, sizeof(table_list));
18891885
table_list.db= table_arg->s->db.str;
18901886
table_list.table_name= table_arg->s->table_name.str;
18911887

sql/records.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ bool init_read_record(READ_RECORD *info,THD *thd,
209209
if (!table)
210210
table= qep_tab->table();
211211

212-
memset(info, 0, sizeof(*info));
212+
new (info) READ_RECORD;
213213
info->thd=thd;
214214
info->table=table;
215215
info->forms= &info->table; /* Only one table */

sql/sql_alter.cc

-1
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,6 @@ bool Sql_cmd_alter_table::execute(THD *thd)
290290
// Rename of table
291291
DBUG_ASSERT(alter_info.flags & Alter_info::ALTER_RENAME);
292292
TABLE_LIST tmp_table;
293-
memset(&tmp_table, 0, sizeof(tmp_table));
294293
tmp_table.table_name= alter_info.new_table_name.str;
295294
tmp_table.db= alter_info.new_db_name.str;
296295
tmp_table.grant.privilege= priv;

sql/sql_delete.cc

-1
Original file line numberDiff line numberDiff line change
@@ -788,7 +788,6 @@ bool Sql_cmd_delete::prepare_inner(THD *thd)
788788
List<Item> fields;
789789
List<Item> all_fields;
790790

791-
memset(&tables, 0, sizeof(tables));
792791
tables.table = table_list->table;
793792
tables.alias = table_list->alias;
794793

sql/sql_insert.cc

-2
Original file line numberDiff line numberDiff line change
@@ -2557,7 +2557,6 @@ static TABLE *create_table_from_items(THD *thd, HA_CREATE_INFO *create_info,
25572557

25582558
DBUG_ENTER("create_table_from_items");
25592559

2560-
memset(&tmp_table, 0, sizeof(tmp_table));
25612560
tmp_table.s= &share;
25622561
init_tmp_table_share(thd, &share, "", 0, "", "", nullptr);
25632562

@@ -2960,7 +2959,6 @@ int Query_result_create::binlog_show_create_table()
29602959
int result;
29612960
TABLE_LIST tmp_table_list;
29622961

2963-
memset(&tmp_table_list, 0, sizeof(tmp_table_list));
29642962
tmp_table_list.table= table;
29652963
query.length(0); // Have to zero it since constructor doesn't
29662964

sql/sql_plugin.cc

+9-10
Original file line numberDiff line numberDiff line change
@@ -945,15 +945,14 @@ static st_plugin_int *plugin_insert_or_reuse(st_plugin_int *plugin)
945945
tmp= *it;
946946
if (tmp->state == PLUGIN_IS_FREED)
947947
{
948-
memcpy(tmp, plugin, sizeof(st_plugin_int));
948+
*tmp = std::move(*plugin);
949949
DBUG_RETURN(tmp);
950950
}
951951
}
952952
if (plugin_array->push_back(plugin))
953953
DBUG_RETURN(NULL);
954954
tmp= plugin_array->back()=
955-
static_cast<st_plugin_int*>(memdup_root(&plugin_mem_root, plugin,
956-
sizeof(st_plugin_int)));
955+
new (&plugin_mem_root) st_plugin_int(std::move(*plugin));
957956
DBUG_RETURN(tmp);
958957
}
959958

@@ -979,8 +978,6 @@ static bool plugin_add(MEM_ROOT *tmp_root,
979978
mysql_mutex_lock(&LOCK_plugin);
980979
DBUG_RETURN(TRUE);
981980
}
982-
/* Clear the whole struct to catch future extensions. */
983-
memset(&tmp, 0, sizeof(tmp));
984981
if (! (tmp.plugin_dl= plugin_dl_add(dl, report)))
985982
DBUG_RETURN(TRUE);
986983
/* Find plugin by name */
@@ -1545,7 +1542,6 @@ bool plugin_register_builtin_and_init_core_se(int *argc, char **argv)
15451542
for (struct st_mysql_plugin *plugin= *builtins; plugin->info; plugin++)
15461543
{
15471544
struct st_plugin_int tmp;
1548-
memset(&tmp, 0, sizeof(tmp));
15491545
tmp.plugin= plugin;
15501546
tmp.name.str= (char *)plugin->name;
15511547
tmp.name.length= strlen(plugin->name);
@@ -1702,8 +1698,7 @@ static bool register_builtin(st_mysql_plugin *plugin,
17021698
DBUG_RETURN(true);
17031699

17041700
*ptr= plugin_array->back()=
1705-
static_cast<st_plugin_int*>(memdup_root(&plugin_mem_root, tmp,
1706-
sizeof(st_plugin_int)));
1701+
new (&plugin_mem_root) st_plugin_int(std::move(*tmp));
17071702

17081703
plugin_hash[plugin->type]->emplace(to_string((*ptr)->name), *ptr);
17091704

@@ -3468,8 +3463,12 @@ static int test_plugin_options(MEM_ROOT *tmp_root, st_plugin_int *tmp,
34683463
bool disable_plugin;
34693464
enum_plugin_load_option plugin_load_option= tmp->load_option;
34703465

3471-
MEM_ROOT *mem_root= alloc_root_inited(&tmp->mem_root) ?
3472-
&tmp->mem_root : &plugin_mem_root;
3466+
/*
3467+
We should use tmp->mem_root here instead of the global plugin_mem_root,
3468+
but tmp->root is not always properly freed, so it will cause leaks in
3469+
Valgrind (e.g. the main.validate_password_plugin test).
3470+
*/
3471+
MEM_ROOT *mem_root= &plugin_mem_root;
34733472
SYS_VAR **opt;
34743473
my_option *opts= NULL;
34753474
LEX_STRING plugin_name;

sql/sql_plugin_ref.h

+8-8
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,15 @@ enum enum_plugin_load_option {
3636

3737
struct st_plugin_int
3838
{
39-
LEX_STRING name;
40-
st_mysql_plugin *plugin;
41-
st_plugin_dl *plugin_dl;
42-
uint state;
43-
uint ref_count; /* number of threads using the plugin */
44-
void *data; /* plugin type specific, e.g. handlerton */
39+
LEX_STRING name{nullptr, 0};
40+
st_mysql_plugin *plugin{nullptr};
41+
st_plugin_dl *plugin_dl{nullptr};
42+
uint state{0};
43+
uint ref_count{0}; /* number of threads using the plugin */
44+
void *data{nullptr}; /* plugin type specific, e.g. handlerton */
4545
MEM_ROOT mem_root; /* memory for dynamic plugin structures */
46-
sys_var *system_vars; /* server variables for this plugin */
47-
enum_plugin_load_option load_option; /* OFF, ON, FORCE, F+PERMANENT */
46+
sys_var *system_vars{nullptr}; /* server variables for this plugin */
47+
enum_plugin_load_option load_option{PLUGIN_OFF}; /* OFF, ON, FORCE, F+PERMANENT */
4848
};
4949

5050
/*

sql/sql_servers.cc

-2
Original file line numberDiff line numberDiff line change
@@ -384,8 +384,6 @@ static bool close_cached_connection_tables(THD *thd,
384384
DBUG_ENTER("close_cached_connection_tables");
385385
DBUG_ASSERT(thd);
386386

387-
memset(&tmp, 0, sizeof(TABLE_LIST));
388-
389387
mysql_mutex_lock(&LOCK_open);
390388

391389
for (const auto &key_and_value : *table_def_cache)

sql/sql_show.cc

-5
Original file line numberDiff line numberDiff line change
@@ -456,10 +456,6 @@ find_files(THD *thd, List<LEX_STRING> *files, const char *db,
456456
wild_length= strlen(wild);
457457
}
458458

459-
460-
461-
memset(&table_list, 0, sizeof(table_list));
462-
463459
if (!(dirp = my_dir(path,MYF(dir ? MY_WANT_STAT : 0))))
464460
{
465461
if (my_errno() == ENOENT)
@@ -3626,7 +3622,6 @@ make_table_name_list(THD *thd, List<LEX_STRING> *table_names, LEX *lex,
36263622
if (!(thd->col_access & TABLE_ACLS))
36273623
{
36283624
TABLE_LIST table_list;
3629-
memset(&table_list, 0, sizeof(table_list));
36303625
table_list.db= db_name->str;
36313626
table_list.db_length= db_name->length;
36323627
table_list.table_name= const_cast<char*>(name->c_str());

sql/sql_tmp_table.cc

+28-16
Original file line numberDiff line numberDiff line change
@@ -2923,12 +2923,24 @@ bool create_ondisk_from_heap(THD *thd, TABLE *wtable,
29232923
table= wtable;
29242924
}
29252925

2926-
/*
2927-
TABLE has no copy ctor; can't use the move ctor as we use both objects
2928-
when we migrate rows.
2929-
*/
29302926
table->mem_root.Clear();
2931-
memcpy(&new_table, table, sizeof(new_table));
2927+
2928+
// Set up a partial copy of the table.
2929+
new_table.record[0]= table->record[0];
2930+
new_table.record[1]= table->record[1];
2931+
new_table.field= table->field;
2932+
new_table.key_info= table->key_info;
2933+
new_table.in_use= table->in_use;
2934+
new_table.db_stat= table->db_stat;
2935+
new_table.key_info= table->key_info;
2936+
new_table.hash_field= table->hash_field;
2937+
new_table.group= table->group;
2938+
new_table.distinct= table->distinct;
2939+
new_table.alias= table->alias;
2940+
new_table.pos_in_table_list= table->pos_in_table_list;
2941+
new_table.reginfo= table->reginfo;
2942+
new_table.read_set= table->read_set;
2943+
new_table.write_set= table->write_set;
29322944

29332945
new_table.s= &share; // New table points to new share
29342946

@@ -3071,19 +3083,19 @@ bool create_ondisk_from_heap(THD *thd, TABLE *wtable,
30713083

30723084
}
30733085

3074-
destroy(table->file);
3075-
table->file=0;
30763086
/*
3077-
'*table' is overwritten with 'new_table'. new_table was set up as
3078-
'*table', so, between the start and end of this function, pointers like
3079-
'table, table->record, table->record[i]' are preserved. This is important,
3080-
for example because some Item_field->field->ptr points into
3081-
table->record[0]: such pointer remains valid after the conversion and
3082-
will allow to access rows of the new TABLE.
3087+
Replace the guts of the old table with the new one, although keeping
3088+
most members.
30833089
*/
3084-
*table= std::move(new_table);
3085-
3086-
// 'table' is now new and points to new share
3090+
destroy(table->file);
3091+
table->s= new_table.s;
3092+
table->file= new_table.file;
3093+
table->db_stat= new_table.db_stat;
3094+
table->in_use= new_table.in_use;
3095+
table->no_rows= new_table.no_rows;
3096+
table->record[0]= new_table.record[0];
3097+
table->record[1]= new_table.record[1];
3098+
table->mem_root= std::move(new_table.mem_root);
30873099

30883100
/*
30893101
Depending on if this TABLE clone is early/late in optimization, or in

sql/sql_view.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ static bool fill_defined_view_parts(THD *thd, TABLE_LIST *view)
267267
const char *cache_key;
268268
size_t cache_key_length= get_table_def_key(view, &cache_key);
269269
TABLE_LIST decoy;
270-
memcpy (&decoy, view, sizeof (TABLE_LIST));
270+
decoy= *view;
271271

272272
mysql_mutex_lock(&LOCK_open);
273273

sql/trigger.cc

-1
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,6 @@ Trigger::Trigger(const LEX_CSTRING &trigger_name,
456456
m_parse_error_message[0]= 0;
457457

458458
construct_definer_value(mem_root, &m_definer, definer_user, definer_host);
459-
memset(&m_subject_table_grant, 0, sizeof (m_subject_table_grant));
460459
}
461460

462461

sql/tztime.cc

+1-3
Original file line numberDiff line numberDiff line change
@@ -1564,10 +1564,9 @@ class Tz_names_entry
15641564
static void
15651565
tz_init_table_list(TABLE_LIST *tz_tabs)
15661566
{
1567-
memset(tz_tabs, 0, sizeof(TABLE_LIST) * MY_TZ_TABLES_COUNT);
1568-
15691567
for (int i= 0; i < MY_TZ_TABLES_COUNT; i++)
15701568
{
1569+
new (&tz_tabs[i]) TABLE_LIST;
15711570
tz_tabs[i].alias= tz_tabs[i].table_name= tz_tables_names[i].str;
15721571
tz_tabs[i].table_name_length= tz_tables_names[i].length;
15731572
tz_tabs[i].db= tz_tables_db_name.str;
@@ -1694,7 +1693,6 @@ my_tz_init(THD *org_thd, const char *default_tzname, bool bootstrap)
16941693
leap seconds shared by all time zones.
16951694
*/
16961695
thd->set_db(db);
1697-
memset(&tz_tables[0], 0, sizeof(TABLE_LIST));
16981696
tz_tables[0].alias= tz_tables[0].table_name=
16991697
(char*)"time_zone_leap_second";
17001698
tz_tables[0].table_name_length= 21;

0 commit comments

Comments
 (0)