mirror of
https://github.com/MariaDB/server.git
synced 2025-08-01 03:47:19 +03:00
Bug#42733: Type-punning warnings when compiling MySQL --
strict aliasing violations. One somewhat major source of strict-aliasing violations and related warnings is the SQL_LIST structure. For example, consider its member function `link_in_list` which takes a pointer to pointer of type T (any type) as a pointer to pointer to unsigned char. Dereferencing this pointer, which is done to reset the next field, violates strict-aliasing rules and might cause problems for surrounding code that uses the next field of the object being added to the list. The solution is to use templates to parametrize the SQL_LIST structure in order to deference the pointers with compatible types. As a side bonus, it becomes possible to remove quite a few casts related to acessing data members of SQL_LIST. sql/handler.h: Use the appropriate template type argument. sql/item.cc: Remove now-unnecessary cast. sql/item_subselect.cc: Remove now-unnecessary casts. sql/item_sum.cc: Use the appropriate template type argument. Remove now-unnecessary cast. sql/mysql_priv.h: Move SQL_LIST structure to sql_list.h Use the appropriate template type argument. sql/sp.cc: Remove now-unnecessary casts. sql/sql_delete.cc: Use the appropriate template type argument. Remove now-unnecessary casts. sql/sql_derived.cc: Remove now-unnecessary casts. sql/sql_lex.cc: Remove now-unnecessary casts. sql/sql_lex.h: SQL_LIST now takes a template type argument which must match the type of the elements of the list. Use forward declaration when the type is not available, it is used in pointers anyway. sql/sql_list.h: Rename SQL_LIST to SQL_I_List. The template parameter is the type of object that is stored in the list. sql/sql_olap.cc: Remove now-unnecessary casts. sql/sql_parse.cc: Remove now-unnecessary casts. sql/sql_prepare.cc: Remove now-unnecessary casts. sql/sql_select.cc: Remove now-unnecessary casts. sql/sql_show.cc: Remove now-unnecessary casts. sql/sql_table.cc: Remove now-unnecessary casts. sql/sql_trigger.cc: Remove now-unnecessary casts. sql/sql_union.cc: Remove now-unnecessary casts. sql/sql_update.cc: Remove now-unnecessary casts. sql/sql_view.cc: Remove now-unnecessary casts. sql/sql_yacc.yy: Remove now-unnecessary casts. storage/myisammrg/ha_myisammrg.cc: Remove now-unnecessary casts.
This commit is contained in:
@ -587,8 +587,8 @@ public:
|
||||
st_lex *parent_lex;
|
||||
enum olap_type olap;
|
||||
/* FROM clause - points to the beginning of the TABLE_LIST::next_local list. */
|
||||
SQL_LIST table_list;
|
||||
SQL_LIST group_list; /* GROUP BY clause. */
|
||||
SQL_I_List<TABLE_LIST> table_list;
|
||||
SQL_I_List<ORDER> group_list; /* GROUP BY clause. */
|
||||
List<Item> item_list; /* list of fields & expressions */
|
||||
List<String> interval_list;
|
||||
bool is_item_list_lookup;
|
||||
@ -610,8 +610,8 @@ public:
|
||||
TABLE_LIST *leaf_tables;
|
||||
const char *type; /* type of select for EXPLAIN */
|
||||
|
||||
SQL_LIST order_list; /* ORDER clause */
|
||||
SQL_LIST *gorder_list;
|
||||
SQL_I_List<ORDER> order_list; /* ORDER clause */
|
||||
SQL_I_List<ORDER> *gorder_list;
|
||||
Item *select_limit, *offset_limit; /* LIMIT clause parameters */
|
||||
// Arrays of pointers to top elements of all_fields list
|
||||
Item **ref_pointer_array;
|
||||
@ -774,7 +774,7 @@ public:
|
||||
{
|
||||
order_list.elements= 0;
|
||||
order_list.first= 0;
|
||||
order_list.next= (uchar**) &order_list.first;
|
||||
order_list.next= &order_list.first;
|
||||
}
|
||||
/*
|
||||
This method created for reiniting LEX in mysql_admin_table() and can be
|
||||
@ -953,6 +953,8 @@ enum xa_option_words {XA_NONE, XA_JOIN, XA_RESUME, XA_ONE_PHASE,
|
||||
XA_SUSPEND, XA_FOR_MIGRATE};
|
||||
|
||||
|
||||
struct Sroutine_hash_entry;
|
||||
|
||||
/*
|
||||
Class representing list of all tables used by statement.
|
||||
It also contains information about stored functions used by statement
|
||||
@ -993,9 +995,9 @@ public:
|
||||
We use these two members for restoring of 'sroutines_list' to the state
|
||||
in which it was right after query parsing.
|
||||
*/
|
||||
SQL_LIST sroutines_list;
|
||||
uchar **sroutines_list_own_last;
|
||||
uint sroutines_list_own_elements;
|
||||
SQL_I_List<Sroutine_hash_entry> sroutines_list;
|
||||
Sroutine_hash_entry **sroutines_list_own_last;
|
||||
uint sroutines_list_own_elements;
|
||||
|
||||
/*
|
||||
These constructor and destructor serve for creation/destruction
|
||||
@ -1599,7 +1601,8 @@ typedef struct st_lex : public Query_tables_list
|
||||
*/
|
||||
List<Name_resolution_context> context_stack;
|
||||
|
||||
SQL_LIST proc_list, auxiliary_table_list, save_list;
|
||||
SQL_I_List<ORDER> proc_list;
|
||||
SQL_I_List<TABLE_LIST> auxiliary_table_list, save_list;
|
||||
Create_field *last_field;
|
||||
Item_sum *in_sum_func;
|
||||
udf_func udf;
|
||||
@ -1721,7 +1724,7 @@ typedef struct st_lex : public Query_tables_list
|
||||
fields to TABLE object at table open (altough for latter pointer to table
|
||||
being opened is probably enough).
|
||||
*/
|
||||
SQL_LIST trg_table_fields;
|
||||
SQL_I_List<Item_trigger_field> trg_table_fields;
|
||||
|
||||
/*
|
||||
stmt_definition_begin is intended to point to the next word after
|
||||
|
Reference in New Issue
Block a user