diff options
author | Monty <monty@mariadb.org> | 2017-04-23 19:39:57 +0300 |
---|---|---|
committer | Monty <monty@mariadb.org> | 2017-04-23 22:35:46 +0300 |
commit | 5a759d31f766087d5e135e1d3d3d987693bc9b88 (patch) | |
tree | 93c7359e8b211e269bfa73e5f595f34b9dca575a /sql/sys_vars.ic | |
parent | cba84469eb96481568a9f4ddf3f2989c49c9294c (diff) | |
download | mariadb-git-5a759d31f766087d5e135e1d3d3d987693bc9b88.tar.gz |
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)
Diffstat (limited to 'sql/sys_vars.ic')
-rw-r--r-- | sql/sys_vars.ic | 108 |
1 files changed, 54 insertions, 54 deletions
diff --git a/sql/sys_vars.ic b/sql/sys_vars.ic index 780450b484b..a157538d528 100644 --- a/sql/sys_vars.ic +++ b/sql/sys_vars.ic @@ -364,9 +364,9 @@ public: { var->save_result.ulonglong_value= option.def_value; } uchar *valptr(THD *thd, ulong val) { return (uchar*)typelib.type_names[val]; } - uchar *session_value_ptr(THD *thd, const LEX_STRING *base) + uchar *session_value_ptr(THD *thd, const LEX_CSTRING *base) { return valptr(thd, session_var(thd, ulong)); } - uchar *global_value_ptr(THD *thd, const LEX_STRING *base) + uchar *global_value_ptr(THD *thd, const LEX_CSTRING *base) { return valptr(thd, global_var(ulong)); } uchar *default_value_ptr(THD *thd) { return valptr(thd, option.def_value); } @@ -619,7 +619,7 @@ public: DBUG_ASSERT(res == 0); } } - uchar *session_value_ptr(THD *thd, const LEX_STRING *base) + uchar *session_value_ptr(THD *thd, const LEX_CSTRING *base) { DBUG_ASSERT(thd != NULL); size_t len= sysvartrack_value_len(thd); @@ -669,7 +669,7 @@ public: void global_save_default(THD *thd, set_var *var) { DBUG_ASSERT(FALSE); } protected: - uchar *session_value_ptr(THD *thd, const LEX_STRING *base) + uchar *session_value_ptr(THD *thd, const LEX_CSTRING *base) { return thd->security_ctx->proxy_user[0] ? (uchar *) &(thd->security_ctx->proxy_user[0]) : NULL; @@ -685,7 +685,7 @@ public: {} protected: - uchar *session_value_ptr(THD *thd, const LEX_STRING *base) + uchar *session_value_ptr(THD *thd, const LEX_CSTRING *base) { return (uchar*)thd->security_ctx->external_user; } @@ -725,7 +725,7 @@ public: bool global_update(THD *thd, set_var *var); protected: - uchar *global_value_ptr(THD *thd, const LEX_STRING *base); + uchar *global_value_ptr(THD *thd, const LEX_CSTRING *base); bool set_filter_value(const char *value, Master_info *mi); }; @@ -736,7 +736,7 @@ protected: Class specific constructor arguments: enum charset_enum is_os_charset_arg - Backing store: LEX_STRING + Backing store: LEX_CSTRING @note Behaves exactly as Sys_var_charptr, only the backing store is different. @@ -757,22 +757,22 @@ public: getopt, is_os_charset_arg, def_val, lock, binlog_status_arg, on_check_func, on_update_func, substitute) { - global_var(LEX_STRING).length= strlen(def_val); - SYSVAR_ASSERT(size == sizeof(LEX_STRING)); + global_var(LEX_CSTRING).length= strlen(def_val); + SYSVAR_ASSERT(size == sizeof(LEX_CSTRING)); *const_cast<SHOW_TYPE*>(&show_val_type)= SHOW_LEX_STRING; } bool global_update(THD *thd, set_var *var) { if (Sys_var_charptr::global_update(thd, var)) return true; - global_var(LEX_STRING).length= var->save_result.string_value.length; + global_var(LEX_CSTRING).length= var->save_result.string_value.length; return false; } }; /* - A LEX_STRING stored only in thd->variables + A LEX_CSTRING stored only in thd->variables Only to be used for small buffers */ @@ -822,10 +822,10 @@ public: } bool session_update(THD *thd, set_var *var) { - LEX_STRING *tmp= &session_var(thd, LEX_STRING); + LEX_CSTRING *tmp= &session_var(thd, LEX_CSTRING); tmp->length= var->save_result.string_value.length; /* Store as \0 terminated string (just to be safe) */ - strmake(tmp->str, var->save_result.string_value.str, tmp->length); + strmake((char*) tmp->str, var->save_result.string_value.str, tmp->length); return false; } bool global_update(THD *thd, set_var *var) @@ -843,7 +843,7 @@ public: { DBUG_ASSERT(FALSE); } - uchar *global_value_ptr(THD *thd, const LEX_STRING *base) + uchar *global_value_ptr(THD *thd, const LEX_CSTRING *base) { DBUG_ASSERT(FALSE); return NULL; @@ -913,13 +913,13 @@ public: char *ptr= (char*)(intptr)option.def_value; var->save_result.string_value.str= ptr; } - uchar *session_value_ptr(THD *thd, const LEX_STRING *base) + uchar *session_value_ptr(THD *thd, const LEX_CSTRING *base) { char buf[256]; DBUG_EXPLAIN(buf, sizeof(buf)); return (uchar*) thd->strdup(buf); } - uchar *global_value_ptr(THD *thd, const LEX_STRING *base) + uchar *global_value_ptr(THD *thd, const LEX_CSTRING *base) { char buf[256]; DBUG_EXPLAIN_INITIAL(buf, sizeof(buf)); @@ -974,7 +974,7 @@ public: bool global_update(THD *thd, set_var *var) { ulonglong new_value= var->save_result.ulonglong_value; - LEX_STRING *base_name= &var->base; + LEX_CSTRING *base_name= &var->base; KEY_CACHE *key_cache; /* If no basename, assume it's for the key cache named 'default' */ @@ -1001,7 +1001,7 @@ public: return keycache_update(thd, key_cache, offset, new_value); } - uchar *global_value_ptr(THD *thd, const LEX_STRING *base) + uchar *global_value_ptr(THD *thd, const LEX_CSTRING *base) { KEY_CACHE *key_cache= get_key_cache(base); if (!key_cache) @@ -1186,7 +1186,7 @@ public: lock, binlog_status_arg, on_check_func, on_update_func, substitute) { } - uchar *session_value_ptr(THD *thd, const LEX_STRING *base) + uchar *session_value_ptr(THD *thd, const LEX_CSTRING *base) { if (thd->user_connect && thd->user_connect->user_resources.user_conn) return (uchar*) &(thd->user_connect->user_resources.user_conn); @@ -1300,9 +1300,9 @@ public: { var->save_result.ulonglong_value= option.def_value; } uchar *valptr(THD *thd, ulonglong val) { return (uchar*)flagset_to_string(thd, 0, val, typelib.type_names); } - uchar *session_value_ptr(THD *thd, const LEX_STRING *base) + uchar *session_value_ptr(THD *thd, const LEX_CSTRING *base) { return valptr(thd, session_var(thd, ulonglong)); } - uchar *global_value_ptr(THD *thd, const LEX_STRING *base) + uchar *global_value_ptr(THD *thd, const LEX_CSTRING *base) { return valptr(thd, global_var(ulonglong)); } uchar *default_value_ptr(THD *thd) { return valptr(thd, option.def_value); } @@ -1399,9 +1399,9 @@ public: { var->save_result.ulonglong_value= option.def_value; } uchar *valptr(THD *thd, ulonglong val) { return (uchar*)set_to_string(thd, 0, val, typelib.type_names); } - uchar *session_value_ptr(THD *thd, const LEX_STRING *base) + uchar *session_value_ptr(THD *thd, const LEX_CSTRING *base) { return valptr(thd, session_var(thd, ulonglong)); } - uchar *global_value_ptr(THD *thd, const LEX_STRING *base) + uchar *global_value_ptr(THD *thd, const LEX_CSTRING *base) { return valptr(thd, global_var(ulonglong)); } uchar *default_value_ptr(THD *thd) { return valptr(thd, option.def_value); } @@ -1450,7 +1450,7 @@ public: var->save_result.plugin= NULL; else { - const LEX_STRING pname= { const_cast<char*>(res->ptr()), res->length() }; + const LEX_CSTRING pname= { const_cast<char*>(res->ptr()), res->length() }; plugin_ref plugin; // special code for storage engines (e.g. to handle historical aliases) @@ -1504,7 +1504,7 @@ public: if (!default_value) return 0; - LEX_STRING pname= { default_value, strlen(pname.str) }; + LEX_CSTRING pname= { default_value, strlen(default_value) }; plugin_ref plugin; if (plugin_type == MYSQL_STORAGE_ENGINE_PLUGIN) @@ -1525,9 +1525,9 @@ public: return (uchar*)(plugin ? thd->strmake(plugin_name(plugin)->str, plugin_name(plugin)->length) : 0); } - uchar *session_value_ptr(THD *thd, const LEX_STRING *base) + uchar *session_value_ptr(THD *thd, const LEX_CSTRING *base) { return valptr(thd, session_var(thd, plugin_ref)); } - uchar *global_value_ptr(THD *thd, const LEX_STRING *base) + uchar *global_value_ptr(THD *thd, const LEX_CSTRING *base) { return valptr(thd, global_var(plugin_ref)); } uchar *default_value_ptr(THD *thd) { return valptr(thd, get_default(thd)); } @@ -1593,11 +1593,11 @@ public: { DBUG_ASSERT(FALSE); } - uchar *session_value_ptr(THD *thd, const LEX_STRING *base) + uchar *session_value_ptr(THD *thd, const LEX_CSTRING *base) { return debug_sync_value_ptr(thd); } - uchar *global_value_ptr(THD *thd, const LEX_STRING *base) + uchar *global_value_ptr(THD *thd, const LEX_CSTRING *base) { DBUG_ASSERT(FALSE); return 0; @@ -1680,9 +1680,9 @@ public: thd->sys_var_tmp.my_bool_value= reverse_semantics ^ ((val & bitmask) != 0); return (uchar*) &thd->sys_var_tmp.my_bool_value; } - uchar *session_value_ptr(THD *thd, const LEX_STRING *base) + uchar *session_value_ptr(THD *thd, const LEX_CSTRING *base) { return valptr(thd, session_var(thd, ulonglong)); } - uchar *global_value_ptr(THD *thd, const LEX_STRING *base) + uchar *global_value_ptr(THD *thd, const LEX_CSTRING *base) { return valptr(thd, global_var(ulonglong)); } uchar *default_value_ptr(THD *thd) { @@ -1743,12 +1743,12 @@ public: { var->value= 0; } void global_save_default(THD *thd, set_var *var) { DBUG_ASSERT(FALSE); } - uchar *session_value_ptr(THD *thd, const LEX_STRING *base) + uchar *session_value_ptr(THD *thd, const LEX_CSTRING *base) { thd->sys_var_tmp.ulonglong_value= read_func(thd); return (uchar*) &thd->sys_var_tmp.ulonglong_value; } - uchar *global_value_ptr(THD *thd, const LEX_STRING *base) + uchar *global_value_ptr(THD *thd, const LEX_CSTRING *base) { DBUG_ASSERT(FALSE); return 0; @@ -1808,13 +1808,13 @@ public: { var->value= 0; } void global_save_default(THD *thd, set_var *var) { DBUG_ASSERT(FALSE); } - uchar *session_value_ptr(THD *thd, const LEX_STRING *base) + uchar *session_value_ptr(THD *thd, const LEX_CSTRING *base) { thd->sys_var_tmp.double_value= thd->start_time + thd->start_time_sec_part/(double)TIME_SECOND_PART_FACTOR; return (uchar*) &thd->sys_var_tmp.double_value; } - uchar *global_value_ptr(THD *thd, const LEX_STRING *base) + uchar *global_value_ptr(THD *thd, const LEX_CSTRING *base) { DBUG_ASSERT(FALSE); return 0; @@ -1878,12 +1878,12 @@ public: } void session_save_default(THD *thd, set_var *var) { } void global_save_default(THD *thd, set_var *var) { } - uchar *session_value_ptr(THD *thd, const LEX_STRING *base) + uchar *session_value_ptr(THD *thd, const LEX_CSTRING *base) { DBUG_ASSERT(FALSE); return 0; } - uchar *global_value_ptr(THD *thd, const LEX_STRING *base) + uchar *global_value_ptr(THD *thd, const LEX_CSTRING *base) { return (uchar*)show_comp_option_name[global_var(enum SHOW_COMP_OPTION)]; } @@ -1955,9 +1955,9 @@ public: } uchar *valptr(THD *thd, uchar *val) { return val ? *(uchar**)(val+name_offset) : 0; } - uchar *session_value_ptr(THD *thd, const LEX_STRING *base) + uchar *session_value_ptr(THD *thd, const LEX_CSTRING *base) { return valptr(thd, session_var(thd, uchar*)); } - uchar *global_value_ptr(THD *thd, const LEX_STRING *base) + uchar *global_value_ptr(THD *thd, const LEX_CSTRING *base) { return valptr(thd, global_var(uchar*)); } uchar *default_value_ptr(THD *thd) { return valptr(thd, *(uchar**)option.def_value); } @@ -2031,7 +2031,7 @@ public: } uchar *valptr(THD *thd, Time_zone *val) { return (uchar *)(val->get_name()->ptr()); } - uchar *session_value_ptr(THD *thd, const LEX_STRING *base) + uchar *session_value_ptr(THD *thd, const LEX_CSTRING *base) { /* This is an ugly fix for replication: we don't replicate properly queries @@ -2044,7 +2044,7 @@ public: thd->time_zone_used= 1; return valptr(thd, session_var(thd, Time_zone *)); } - uchar *global_value_ptr(THD *thd, const LEX_STRING *base) + uchar *global_value_ptr(THD *thd, const LEX_CSTRING *base) { return valptr(thd, global_var(Time_zone*)); } uchar *default_value_ptr(THD *thd) { return valptr(thd, *(Time_zone**)option.def_value); } @@ -2215,7 +2215,7 @@ public: /* Use value given in variable declaration */ global_save_default(thd, var); } - uchar *session_value_ptr(THD *thd, const LEX_STRING *base) + uchar *session_value_ptr(THD *thd, const LEX_CSTRING *base) { ulonglong *tmp, res; tmp= (ulonglong*) (((uchar*)&(thd->variables)) + offset); @@ -2223,7 +2223,7 @@ public: *tmp= res; return (uchar*) tmp; } - uchar *global_value_ptr(THD *thd, const LEX_STRING *base) + uchar *global_value_ptr(THD *thd, const LEX_CSTRING *base) { return session_value_ptr(thd, base); } @@ -2275,12 +2275,12 @@ public: { DBUG_ASSERT(false); } - uchar *session_value_ptr(THD *thd, const LEX_STRING *base) + uchar *session_value_ptr(THD *thd, const LEX_CSTRING *base) { DBUG_ASSERT(false); return NULL; } - uchar *global_value_ptr(THD *thd, const LEX_STRING *base); + uchar *global_value_ptr(THD *thd, const LEX_CSTRING *base); }; @@ -2324,12 +2324,12 @@ public: { DBUG_ASSERT(false); } - uchar *session_value_ptr(THD *thd, const LEX_STRING *base) + uchar *session_value_ptr(THD *thd, const LEX_CSTRING *base) { DBUG_ASSERT(false); return NULL; } - uchar *global_value_ptr(THD *thd, const LEX_STRING *base); + uchar *global_value_ptr(THD *thd, const LEX_CSTRING *base); }; @@ -2364,12 +2364,12 @@ public: /* Record the attempt to use default so we can error. */ var->value= 0; } - uchar *session_value_ptr(THD *thd, const LEX_STRING *base) + uchar *session_value_ptr(THD *thd, const LEX_CSTRING *base) { DBUG_ASSERT(false); return NULL; } - uchar *global_value_ptr(THD *thd, const LEX_STRING *base); + uchar *global_value_ptr(THD *thd, const LEX_CSTRING *base); uchar *default_value_ptr(THD *thd) { return 0; } }; @@ -2406,12 +2406,12 @@ public: /* Record the attempt to use default so we can error. */ var->value= 0; } - uchar *session_value_ptr(THD *thd, const LEX_STRING *base) + uchar *session_value_ptr(THD *thd, const LEX_CSTRING *base) { DBUG_ASSERT(false); return NULL; } - uchar *global_value_ptr(THD *thd, const LEX_STRING *base); + uchar *global_value_ptr(THD *thd, const LEX_CSTRING *base); uchar *default_value_ptr(THD *thd) { return 0; } }; @@ -2456,8 +2456,8 @@ public: { DBUG_ASSERT(false); } - uchar *session_value_ptr(THD *thd, const LEX_STRING *base); - uchar *global_value_ptr(THD *thd, const LEX_STRING *base) + uchar *session_value_ptr(THD *thd, const LEX_CSTRING *base); + uchar *global_value_ptr(THD *thd, const LEX_CSTRING *base) { DBUG_ASSERT(false); return NULL; @@ -2483,5 +2483,5 @@ public: SYSVAR_ASSERT(scope() == GLOBAL); } bool global_update(THD *thd, set_var *var); - uchar *global_value_ptr(THD *thd, const LEX_STRING *base); + uchar *global_value_ptr(THD *thd, const LEX_CSTRING *base); }; |