Skip to content
Permalink
Browse files
fix gcc 8 compiler warnings
There were two newly enabled warnings:
1. cast for a function pointers. Affected sql_analyse.h, mi_write.c
   and ma_write.cc, mf_iocache-t.cc, mysqlbinlog.cc, encryption.cc, etc

2. memcpy/memset of nontrivial structures. Fixed as:
* the warning disabled for InnoDB
* TABLE, TABLE_SHARE, and TABLE_LIST got a new method reset() which
  does the bzero(), which is safe for these classes, but any other
  bzero() will still cause a warning
* Table_scope_and_contents_source_st uses `TABLE_LIST *` (trivial)
  instead of `SQL_I_List<TABLE_LIST>` (not trivial) so it's safe to
  bzero now.
* added casts in debug_sync.cc and sql_select.cc (for JOIN)
* move assignment method for MDL_request instead of memcpy()
* PARTIAL_INDEX_INTERSECT_INFO::init() instead of bzero()
* remove constructor from READ_RECORD() to make it trivial
* replace some memcpy() with c++ copy assignments
  • Loading branch information
vuvova committed Mar 14, 2019
1 parent ddfa722 commit 3d2d060
Show file tree
Hide file tree
Showing 33 changed files with 166 additions and 136 deletions.
@@ -2867,16 +2867,25 @@ void *sql_alloc(size_t size)
return alloc_root(&s_mem_root, size);
}

uint e_key_get_latest_version_func(uint) { return 1; }
uint e_key_get_func(uint, uint, uchar*, uint*) { return 1; }
uint e_ctx_size_func(uint, uint) { return 1; }
int e_ctx_init_func(void *, const uchar*, uint, const uchar*, uint,
int, uint, uint) { return 1; }
int e_ctx_update_func(void *, const uchar*, uint, uchar*, uint*) { return 1; }
int e_ctx_finish_func(void *, uchar*, uint*) { return 1; }
uint e_encrypted_length_func(uint, uint, uint) { return 1; }

uint dummy1() { return 1; }
struct encryption_service_st encryption_handler=
{
(uint(*)(uint))dummy1,
(uint(*)(uint, uint, uchar*, uint*))dummy1,
(uint(*)(uint, uint))dummy1,
(int (*)(void*, const uchar*, uint, const uchar*, uint, int, uint, uint))dummy1,
(int (*)(void*, const uchar*, uint, uchar*, uint*))dummy1,
(int (*)(void*, uchar*, uint*))dummy1,
(uint (*)(uint, uint, uint))dummy1
e_key_get_latest_version_func,
e_key_get_func,
e_ctx_size_func,
e_ctx_init_func,
e_ctx_update_func,
e_ctx_finish_func,
e_encrypted_length_func
};

/*
@@ -584,7 +584,7 @@ static void debug_sync_remove_action(st_debug_sync_control *ds_control,
memmove(save_action, action, sizeof(st_debug_sync_action));

/* Move actions down. */
memmove(ds_control->ds_action + dsp_idx,
memmove((void*)(ds_control->ds_action + dsp_idx),
ds_control->ds_action + dsp_idx + 1,
(ds_control->ds_active - dsp_idx) *
sizeof(st_debug_sync_action));
@@ -595,8 +595,8 @@ static void debug_sync_remove_action(st_debug_sync_control *ds_control,
produced by the shift. Again do not use an assignment operator to
avoid string allocation/copy.
*/
memmove(ds_control->ds_action + ds_control->ds_active, save_action,
sizeof(st_debug_sync_action));
memmove((void*)(ds_control->ds_action + ds_control->ds_active),
save_action, sizeof(st_debug_sync_action));
}

DBUG_VOID_RETURN;
@@ -25,6 +25,10 @@ struct encryption_service_st encryption_handler;

extern "C" {

uint no_get_key(uint, uint, uchar*, uint*)
{
return ENCRYPTION_KEY_VERSION_INVALID;
}
uint no_key(uint)
{
return ENCRYPTION_KEY_VERSION_INVALID;
@@ -47,6 +51,11 @@ static unsigned int get_length(unsigned int slen, unsigned int key_id,
return my_aes_get_size(MY_AES_CBC, slen);
}

uint ctx_size(unsigned int, unsigned int)
{
return MY_AES_CTX_SIZE;
}

} /* extern "C" */

int initialize_encryption_plugin(st_plugin_int *plugin)
@@ -72,8 +81,7 @@ int initialize_encryption_plugin(st_plugin_int *plugin)
if (handle->crypt_ctx_size)
encryption_handler.encryption_ctx_size_func= handle->crypt_ctx_size;
else
encryption_handler.encryption_ctx_size_func=
(uint (*)(unsigned int, unsigned int))my_aes_ctx_size;
encryption_handler.encryption_ctx_size_func= ctx_size;

encryption_handler.encryption_ctx_init_func=
handle->crypt_ctx_init ? handle->crypt_ctx_init : ctx_init;
@@ -102,8 +110,7 @@ int finalize_encryption_plugin(st_plugin_int *plugin)

if (used)
{
encryption_handler.encryption_key_get_func=
(uint (*)(uint, uint, uchar*, uint*))no_key;
encryption_handler.encryption_key_get_func= no_get_key;
encryption_handler.encryption_key_get_latest_version_func= no_key;
encryption_handler.encryption_ctx_size_func= zero_size;
}
@@ -1687,7 +1687,6 @@ struct Table_scope_and_contents_source_st
uint options; /* OR of HA_CREATE_ options */
uint merge_insert_method;
uint extra_size; /* length of extra data segment */
SQL_I_List<TABLE_LIST> merge_list;
handlerton *db_type;
/**
Row type of the table definition.
@@ -1716,6 +1715,7 @@ struct Table_scope_and_contents_source_st
TABLE_LIST *pos_in_locked_tables;
MDL_ticket *mdl_ticket;
bool table_was_deleted;
TABLE_LIST *merge_list;

void init()
{
@@ -475,6 +475,16 @@ class MDL_request
DBUG_ASSERT(ticket == NULL);
type= type_arg;
}
void move_from(MDL_request &from)
{
type= from.type;
duration= from.duration;
ticket= from.ticket;
next_in_list= from.next_in_list;
prev_in_list= from.prev_in_list;
key.mdl_key_init(&from.key);
from.ticket= NULL; // that's what "move" means
}

/*
This is to work around the ugliness of TABLE_LIST
@@ -1340,8 +1340,7 @@ QUICK_RANGE_SELECT::~QUICK_RANGE_SELECT()
- Use rowids from unique to run a disk-ordered sweep
*/

QUICK_INDEX_SORT_SELECT::QUICK_INDEX_SORT_SELECT(THD *thd_param,
TABLE *table)
QUICK_INDEX_SORT_SELECT::QUICK_INDEX_SORT_SELECT(THD *thd_param, TABLE *table)
:unique(NULL), pk_quick_select(NULL), thd(thd_param)
{
DBUG_ENTER("QUICK_INDEX_SORT_SELECT::QUICK_INDEX_SORT_SELECT");
@@ -5111,6 +5110,16 @@ typedef struct st_partial_index_intersect_info
key_map filtered_scans; /* scans to be filtered by cpk conditions */

MY_BITMAP *intersect_fields; /* bitmap of fields used in intersection */

void init()
{
common_info= NULL;
intersect_fields= NULL;
records_sent_to_unique= records= length= in_memory= use_cpk_filter= 0;
cost= index_read_cost= in_memory_cost= 0.0;
filtered_scans.init();
filtered_scans.clear_all();
}
} PARTIAL_INDEX_INTERSECT_INFO;


@@ -5247,8 +5256,7 @@ bool prepare_search_best_index_intersect(PARAM *param,
if (!n_index_scans)
return 1;

bzero(init, sizeof(*init));
init->filtered_scans.init();
init->init();
init->common_info= common;
init->cost= cutoff_cost;

@@ -47,7 +47,7 @@ partition_info *partition_info::get_clone(THD *thd)
mem_alloc_error(sizeof(partition_info));
DBUG_RETURN(NULL);
}
memcpy(clone, this, sizeof(partition_info));
*clone= *this;
memset(&(clone->read_partitions), 0, sizeof(clone->read_partitions));
memset(&(clone->lock_partitions), 0, sizeof(clone->lock_partitions));
clone->bitmaps_are_initialized= FALSE;
@@ -63,7 +63,7 @@ partition_info *partition_info::get_clone(THD *thd)
mem_alloc_error(sizeof(partition_element));
DBUG_RETURN(NULL);
}
memcpy(part_clone, part, sizeof(partition_element));
*part_clone= *part;
part_clone->subpartitions.empty();
while ((subpart= (subpart_it++)))
{
@@ -73,7 +73,7 @@ partition_info *partition_info::get_clone(THD *thd)
mem_alloc_error(sizeof(partition_element));
DBUG_RETURN(NULL);
}
memcpy(subpart_clone, subpart, sizeof(partition_element));
*subpart_clone= *subpart;
part_clone->subpartitions.push_back(subpart_clone, mem_root);
}
clone->partitions.push_back(part_clone, mem_root);
@@ -1897,12 +1897,11 @@ void partition_info::print_no_partition_found(TABLE *table_arg, myf errflag)
TABLE_LIST table_list;
THD *thd= current_thd;

bzero(&table_list, sizeof(table_list));
table_list.reset();
table_list.db= table_arg->s->db.str;
table_list.table_name= table_arg->s->table_name.str;

if (check_single_table_access(thd,
SELECT_ACL, &table_list, TRUE))
if (check_single_table_access(thd, SELECT_ACL, &table_list, TRUE))
{
my_message(ER_NO_PARTITION_FOR_GIVEN_VALUE,
ER_THD(thd, ER_NO_PARTITION_FOR_GIVEN_VALUE_SILENT), errflag);
@@ -69,8 +69,6 @@ struct READ_RECORD
*/
Copy_field *copy_field;
Copy_field *copy_field_end;
public:
READ_RECORD() {}
};

bool init_read_record(READ_RECORD *info, THD *thd, TABLE *reg_form,
@@ -8538,11 +8538,13 @@ static int open_grant_tables(THD *thd, TABLE_LIST *tables,
}

int prev= -1;
bzero(tables, sizeof(TABLE_LIST) * TABLES_MAX);
for (int cur=TABLES_MAX-1, mask= 1 << cur; mask; cur--, mask >>= 1)
{
if ((tables_to_open & mask) == 0)
{
tables[cur].table= NULL;
continue;
}
tables[cur].init_one_table(C_STRING_WITH_LEN("mysql"),
acl_table_names[cur].str,
acl_table_names[cur].length,
@@ -233,7 +233,7 @@ bool Sql_cmd_alter_table::execute(THD *thd)
DBUG_RETURN(TRUE); /* purecov: inspected */

/* If it is a merge table, check privileges for merge children. */
if (create_info.merge_list.first)
if (create_info.merge_list)
{
/*
The user must have (SELECT_ACL | UPDATE_ACL | DELETE_ACL) on the
@@ -271,7 +271,7 @@ bool Sql_cmd_alter_table::execute(THD *thd)
*/

if (check_table_access(thd, SELECT_ACL | UPDATE_ACL | DELETE_ACL,
create_info.merge_list.first, FALSE, UINT_MAX, FALSE))
create_info.merge_list, FALSE, UINT_MAX, FALSE))
DBUG_RETURN(TRUE);
}

@@ -282,9 +282,9 @@ bool Sql_cmd_alter_table::execute(THD *thd)
{
// Rename of table
TABLE_LIST tmp_table;
memset(&tmp_table, 0, sizeof(tmp_table));
tmp_table.table_name= lex->name.str;
tmp_table.db= select_lex->db;
tmp_table.init_one_table(select_lex->db, strlen(select_lex->db),
lex->name.str, lex->name.length,
lex->name.str, TL_IGNORE);
tmp_table.grant.privilege= priv;
if (check_grant(thd, INSERT_ACL | CREATE_ACL, &tmp_table, FALSE,
UINT_MAX, FALSE))
@@ -298,9 +298,9 @@ bool get_ev_num_info(EV_NUM_INFO *ev_info, NUM_INFO *info, const char *num)
} // get_ev_num_info


void free_string(String *s)
void free_string(void* str, TREE_FREE, void*)
{
s->free();
((String*)str)->free();
}


@@ -68,7 +68,7 @@ int compare_ulonglong2(void* cmp_arg __attribute__((unused)),
int compare_decimal2(int* len, const char *s, const char *t);
Procedure *proc_analyse_init(THD *thd, ORDER *param, select_result *result,
List<Item> &field_list);
void free_string(String*);
void free_string(void* str, TREE_FREE, void*);
class analyse;

class field_info :public Sql_alloc
@@ -121,8 +121,7 @@ class field_str :public field_info
must_be_blob(0), was_zero_fill(0),
was_maybe_zerofill(0), can_be_still_num(1)
{ init_tree(&tree, 0, 0, sizeof(String), (qsort_cmp2) sortcmp2,
(tree_element_free) free_string, NULL,
MYF(MY_THREAD_SPECIFIC)); };
free_string, NULL, MYF(MY_THREAD_SPECIFIC)); };

void add();
void get_opt_type(String*, ha_rows);
@@ -359,8 +359,6 @@ bool mysql_ha_open(THD *thd, TABLE_LIST *tables, SQL_HANDLER *reopen)
sql_handler->reset();
}
sql_handler->table= table;
memcpy(&sql_handler->mdl_request, &tables->mdl_request,
sizeof(tables->mdl_request));

if (!(sql_handler->lock= get_lock_data(thd, &sql_handler->table, 1,
GET_LOCK_STORE_LOCKS)))
@@ -374,6 +372,8 @@ bool mysql_ha_open(THD *thd, TABLE_LIST *tables, SQL_HANDLER *reopen)
if (error)
goto err;

sql_handler->mdl_request.move_from(tables->mdl_request);

/* Always read all columns */
table->read_set= &table->s->all_set;
if (table->vcol_set)
@@ -403,9 +403,6 @@ bool mysql_ha_open(THD *thd, TABLE_LIST *tables, SQL_HANDLER *reopen)
*/
table->open_by_handler= 1;

/* Safety, cleanup the pointer to satisfy MDL assertions. */
tables->mdl_request.ticket= NULL;

if (! reopen)
my_ok(thd);
DBUG_PRINT("exit",("OK"));
@@ -4319,14 +4319,12 @@ select_create::binlog_show_create_table(TABLE **tables, uint count)
DBUG_ASSERT(thd->is_current_stmt_binlog_format_row());
DBUG_ASSERT(tables && *tables && count > 0);

char buf[2048];
String query(buf, sizeof(buf), system_charset_info);
StringBuffer<2048> query(system_charset_info);
int result;
TABLE_LIST tmp_table_list;

memset(&tmp_table_list, 0, sizeof(tmp_table_list));
tmp_table_list.reset();
tmp_table_list.table = *tables;
query.length(0); // Have to zero it since constructor doesn't

result= show_create_table(thd, &tmp_table_list, &query,
create_info, WITH_DB_NAME);
@@ -8948,7 +8948,7 @@ bool create_table_precheck(THD *thd, TABLE_LIST *tables,
goto err;

/* If it is a merge table, check privileges for merge children. */
if (lex->create_info.merge_list.first)
if (lex->create_info.merge_list)
{
/*
The user must have (SELECT_ACL | UPDATE_ACL | DELETE_ACL) on the
@@ -8986,8 +8986,7 @@ bool create_table_precheck(THD *thd, TABLE_LIST *tables,
*/

if (check_table_access(thd, SELECT_ACL | UPDATE_ACL | DELETE_ACL,
lex->create_info.merge_list.first,
FALSE, UINT_MAX, FALSE))
lex->create_info.merge_list, FALSE, UINT_MAX, FALSE))
goto err;
}

0 comments on commit 3d2d060

Please sign in to comment.