1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-27 18:02:13 +03:00

Changing field::field_name and Item::name to LEX_CSTRING

Benefits of this patch:
- Removed a lot of calls to strlen(), especially for field_string
- Strings generated by parser are now const strings, less chance of
  accidently changing a string
- Removed a lot of calls with LEX_STRING as parameter (changed to pointer)
- More uniform code
- Item::name_length was not kept up to date. Now fixed
- Several bugs found and fixed (Access to null pointers,
  access of freed memory, wrong arguments to printf like functions)
- Removed a lot of casts from (const char*) to (char*)

Changes:
- This caused some ABI changes
  - lex_string_set now uses LEX_CSTRING
  - Some fucntions are now taking const char* instead of char*
- Create_field::change and after changed to LEX_CSTRING
- handler::connect_string, comment and engine_name() changed to LEX_CSTRING
- Checked printf() related calls to find bugs. Found and fixed several
  errors in old code.
- A lot of changes from LEX_STRING to LEX_CSTRING, especially related to
  parsing and events.
- Some changes from LEX_STRING and LEX_STRING & to LEX_CSTRING*
- Some changes for char* to const char*
- Added printf argument checking for my_snprintf()
- Introduced null_clex_str, star_clex_string, temp_lex_str to simplify
  code
- Added item_empty_name and item_used_name to be able to distingush between
  items that was given an empty name and items that was not given a name
  This is used in sql_yacc.yy to know when to give an item a name.
- select table_name."*' is not anymore same as table_name.*
- removed not used function Item::rename()
- Added comparision of item->name_length before some calls to
  my_strcasecmp() to speed up comparison
- Moved Item_sp_variable::make_field() from item.h to item.cc
- Some minimal code changes to avoid copying to const char *
- Fixed wrong error message in wsrep_mysql_parse()
- Fixed wrong code in find_field_in_natural_join() where real_item() was
  set when it shouldn't
- ER_ERROR_ON_RENAME was used with extra arguments.
- Removed some (wrong) ER_OUTOFMEMORY, as alloc_root will already
  give the error.

TODO:
- Check possible unsafe casts in plugin/auth_examples/qa_auth_interface.c
- Change code to not modify LEX_CSTRING for database name
  (as part of lower_case_table_names)
This commit is contained in:
Monty
2017-04-23 19:39:57 +03:00
parent cba84469eb
commit 5a759d31f7
233 changed files with 4155 additions and 3794 deletions

View File

@ -371,16 +371,14 @@ static bool exchange_name_with_ddl_log(THD *thd,
/* call rename table from table to tmp-name */
DBUG_EXECUTE_IF("exchange_partition_fail_3",
my_error(ER_ERROR_ON_RENAME, MYF(0),
name, tmp_name, 0, "n/a");
name, tmp_name, 0);
error_set= TRUE;
goto err_rename;);
DBUG_EXECUTE_IF("exchange_partition_abort_3", DBUG_SUICIDE(););
if (file->ha_rename_table(name, tmp_name))
{
char errbuf[MYSYS_STRERROR_SIZE];
my_strerror(errbuf, sizeof(errbuf), my_errno);
my_error(ER_ERROR_ON_RENAME, MYF(0), name, tmp_name,
my_errno, errbuf);
my_errno);
error_set= TRUE;
goto err_rename;
}
@ -392,16 +390,13 @@ static bool exchange_name_with_ddl_log(THD *thd,
/* call rename table from partition to table */
DBUG_EXECUTE_IF("exchange_partition_fail_5",
my_error(ER_ERROR_ON_RENAME, MYF(0),
from_name, name, 0, "n/a");
from_name, name, 0);
error_set= TRUE;
goto err_rename;);
DBUG_EXECUTE_IF("exchange_partition_abort_5", DBUG_SUICIDE(););
if (file->ha_rename_table(from_name, name))
{
char errbuf[MYSYS_STRERROR_SIZE];
my_strerror(errbuf, sizeof(errbuf), my_errno);
my_error(ER_ERROR_ON_RENAME, MYF(0), from_name, name,
my_errno, errbuf);
my_error(ER_ERROR_ON_RENAME, MYF(0), from_name, name, my_errno);
error_set= TRUE;
goto err_rename;
}
@ -413,16 +408,13 @@ static bool exchange_name_with_ddl_log(THD *thd,
/* call rename table from tmp-nam to partition */
DBUG_EXECUTE_IF("exchange_partition_fail_7",
my_error(ER_ERROR_ON_RENAME, MYF(0),
tmp_name, from_name, 0, "n/a");
tmp_name, from_name, 0);
error_set= TRUE;
goto err_rename;);
DBUG_EXECUTE_IF("exchange_partition_abort_7", DBUG_SUICIDE(););
if (file->ha_rename_table(tmp_name, from_name))
{
char errbuf[MYSYS_STRERROR_SIZE];
my_strerror(errbuf, sizeof(errbuf), my_errno);
my_error(ER_ERROR_ON_RENAME, MYF(0), tmp_name, from_name,
my_errno, errbuf);
my_error(ER_ERROR_ON_RENAME, MYF(0), tmp_name, from_name, my_errno);
error_set= TRUE;
goto err_rename;
}
@ -491,7 +483,7 @@ bool Sql_cmd_alter_table_exchange_partition::
TABLE_LIST *swap_table_list;
handlerton *table_hton;
partition_element *part_elem;
char *partition_name;
const char *partition_name;
char temp_name[FN_REFLEN+1];
char part_file_name[FN_REFLEN+1];
char swap_file_name[FN_REFLEN+1];
@ -579,7 +571,7 @@ bool Sql_cmd_alter_table_exchange_partition::
swap_table_list->table_name,
"", 0);
/* create a unique temp name #sqlx-nnnn_nnnn, x for eXchange */
my_snprintf(temp_name, sizeof(temp_name), "%sx-%lx_%lx",
my_snprintf(temp_name, sizeof(temp_name), "%sx-%lx_%llx",
tmp_file_prefix, current_pid, thd->thread_id);
if (lower_case_table_names)
my_casedn_str(files_charset_info, temp_name);
@ -808,11 +800,11 @@ bool Sql_cmd_alter_table_truncate_partition::execute(THD *thd)
Prune all, but named partitions,
to avoid excessive calls to external_lock().
*/
List_iterator<char> partition_names_it(alter_info->partition_names);
List_iterator<const char> partition_names_it(alter_info->partition_names);
uint num_names= alter_info->partition_names.elements;
for (i= 0; i < num_names; i++)
{
char *partition_name= partition_names_it++;
const char *partition_name= partition_names_it++;
String *str_partition_name= new (thd->mem_root)
String(partition_name, system_charset_info);
if (!str_partition_name)