Skip to content

Commit 6632ed9

Browse files
committed
Bug#29806684: REMOVE UNNECESSARY CONST_CAST [noclose]
Remove unnecessary explicit const_cast. Follow-up to Bug#28787273: FIX -WCAST-QUAL COMPILATION WARNINGS. Patch 3. Change-Id: I71e81cd7ba34c9e244f2dedd6960dfb2dc8404b9
1 parent d4bfba7 commit 6632ed9

27 files changed

+74
-81
lines changed

Diff for: sql/auth/auth_common.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -675,7 +675,7 @@ bool acl_check_host(THD *thd, const char *host, const char *ip);
675675
void log_user(THD *thd, String *str, LEX_USER *user, bool comma);
676676
bool check_change_password(THD *thd, const char *host, const char *user,
677677
bool retain_current_password);
678-
bool change_password(THD *thd, LEX_USER *user, char *password,
678+
bool change_password(THD *thd, LEX_USER *user, const char *password,
679679
const char *current_password,
680680
bool retain_current_password);
681681
bool mysql_create_user(THD *thd, List<LEX_USER> &list, bool if_not_exists,

Diff for: sql/auth/sql_user.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1304,7 +1304,7 @@ bool set_and_validate_user_attributes(
13041304
@retval 1 ERROR; In this case the error is sent to the client.
13051305
*/
13061306

1307-
bool change_password(THD *thd, LEX_USER *lex_user, char *new_password,
1307+
bool change_password(THD *thd, LEX_USER *lex_user, const char *new_password,
13081308
const char *current_password,
13091309
bool retain_current_password) {
13101310
TABLE_LIST tables[ACL_TABLES::LAST_ENTRY];

Diff for: sql/dd/dd_table.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -743,7 +743,7 @@ bool fill_dd_columns_from_create_fields(THD *thd, dd::Abstract_table *tab_obj,
743743

744744
// Reset the buffer and assign the column's default value.
745745
memset(buf, 0, bufsize);
746-
if (prepare_default_value(thd, buf, table, field, col_obj)) return true;
746+
if (prepare_default_value(thd, buf, &table, field, col_obj)) return true;
747747

748748
/**
749749
Storing default value specified for column in

Diff for: sql/dd_table_share.cc

+2-3
Original file line numberDiff line numberDiff line change
@@ -541,9 +541,8 @@ static bool fill_tablespace_from_dd(THD *thd, TABLE_SHARE *share,
541541
const dd::Table *tab_obj) {
542542
DBUG_TRACE;
543543

544-
return dd::get_tablespace_name<dd::Table>(
545-
thd, tab_obj, const_cast<const char **>(&share->tablespace),
546-
&share->mem_root);
544+
return dd::get_tablespace_name<dd::Table>(thd, tab_obj, &share->tablespace,
545+
&share->mem_root);
547546
}
548547

549548
/**

Diff for: sql/default_values.cc

+3-3
Original file line numberDiff line numberDiff line change
@@ -184,16 +184,16 @@ size_t max_pack_length(const List<Create_field> &create_fields) {
184184
return max_pack_length;
185185
}
186186

187-
bool prepare_default_value(THD *thd, uchar *buf, const TABLE &table,
187+
bool prepare_default_value(THD *thd, uchar *buf, TABLE *table,
188188
const Create_field &field, dd::Column *col_obj) {
189189
// Create a fake field with a real data buffer in which to store the value.
190-
Field *regfield = make_field(field, table.s, buf + 1, buf, 0 /* null_bit */);
190+
Field *regfield = make_field(field, table->s, buf + 1, buf, 0 /* null_bit */);
191191

192192
bool retval = true;
193193
if (!regfield) goto err;
194194

195195
// save_in_field() will access regfield->table->in_use.
196-
regfield->init(const_cast<TABLE *>(&table));
196+
regfield->init(table);
197197

198198
// Set if the field may be NULL.
199199
if (!(field.flags & NOT_NULL_FLAG)) regfield->set_null();

Diff for: sql/default_values.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
1+
/* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
22
33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License, version 2.0,
@@ -79,7 +79,7 @@ size_t max_pack_length(const List<Create_field> &create_fields);
7979
@retval false Success.
8080
*/
8181

82-
bool prepare_default_value(THD *thd, uchar *buf, const TABLE &table,
82+
bool prepare_default_value(THD *thd, uchar *buf, TABLE *table,
8383
const Create_field &field, dd::Column *col_obj);
8484

8585
/**

Diff for: sql/handler.cc

+5-5
Original file line numberDiff line numberDiff line change
@@ -7392,17 +7392,17 @@ uint calculate_key_len(TABLE *table, uint key, key_part_map keypart_map) {
73927392
pointer pointer to TYPELIB structure
73937393
*/
73947394
static bool exts_handlerton(THD *, plugin_ref plugin, void *arg) {
7395-
List<char> *found_exts = (List<char> *)arg;
7395+
List<const char> *found_exts = static_cast<List<const char> *>(arg);
73967396
handlerton *hton = plugin_data<handlerton *>(plugin);
73977397
if (hton->state == SHOW_OPTION_YES && hton->file_extensions) {
7398-
List_iterator_fast<char> it(*found_exts);
7398+
List_iterator_fast<const char> it(*found_exts);
73997399
const char **ext, *old_ext;
74007400

74017401
for (ext = hton->file_extensions; *ext; ext++) {
74027402
while ((old_ext = it++)) {
74037403
if (!strcmp(old_ext, *ext)) break;
74047404
}
7405-
if (!old_ext) found_exts->push_back(const_cast<char *>(*ext));
7405+
if (!old_ext) found_exts->push_back(*ext);
74067406

74077407
it.rewind();
74087408
}
@@ -7415,7 +7415,7 @@ TYPELIB *ha_known_exts() {
74157415
known_extensions->name = "known_exts";
74167416
known_extensions->type_lengths = NULL;
74177417

7418-
List<char> found_exts;
7418+
List<const char> found_exts;
74197419
const char **ext, *old_ext;
74207420

74217421
plugin_foreach(NULL, exts_handlerton, MYSQL_STORAGE_ENGINE_PLUGIN,
@@ -7428,7 +7428,7 @@ TYPELIB *ha_known_exts() {
74287428
known_extensions->count = found_exts.elements;
74297429
known_extensions->type_names = ext;
74307430

7431-
List_iterator_fast<char> it(found_exts);
7431+
List_iterator_fast<const char> it(found_exts);
74327432
while ((old_ext = it++)) *ext++ = old_ext;
74337433
*ext = NULL;
74347434
return known_extensions;

Diff for: sql/item_func.cc

+4-4
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,10 @@ using std::min;
132132

133133
static void free_user_var(user_var_entry *entry) { entry->destroy(); }
134134

135-
bool check_reserved_words(LEX_STRING *name) {
136-
if (!my_strcasecmp(system_charset_info, name->str, "GLOBAL") ||
137-
!my_strcasecmp(system_charset_info, name->str, "LOCAL") ||
138-
!my_strcasecmp(system_charset_info, name->str, "SESSION"))
135+
bool check_reserved_words(const char *name) {
136+
if (!my_strcasecmp(system_charset_info, name, "GLOBAL") ||
137+
!my_strcasecmp(system_charset_info, name, "LOCAL") ||
138+
!my_strcasecmp(system_charset_info, name, "SESSION"))
139139
return true;
140140
return false;
141141
}

Diff for: sql/item_func.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -3791,7 +3791,7 @@ class Item_func_version final : public Item_static_string_func {
37913791

37923792
Item *get_system_var(Parse_context *pc, enum_var_type var_type, LEX_STRING name,
37933793
LEX_STRING component);
3794-
extern bool check_reserved_words(LEX_STRING *name);
3794+
extern bool check_reserved_words(const char *name);
37953795
extern enum_field_types agg_field_type(Item **items, uint nitems);
37963796
double my_double_round(double value, longlong dec, bool dec_unsigned,
37973797
bool truncate);

Diff for: sql/item_geofunc_buffer.cc

+1-2
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,7 @@ String *Item_func_buffer_strategy::val_str(String * /* str_arg */) {
198198
tmp_value.set_charset(&my_charset_bin);
199199
// The tmp_value is supposed to always stores a {uint32,double} pair,
200200
// and it uses a char tmp_buffer[16] array data member.
201-
uchar *result_buf =
202-
const_cast<uchar *>(pointer_cast<const uchar *>(tmp_value.ptr()));
201+
uchar *result_buf = pointer_cast<uchar *>(tmp_value.ptr());
203202

204203
// Although the result of this item node is never persisted, we still have to
205204
// use portable endianess access otherwise unaligned access will crash

Diff for: sql/item_geofunc_internal.cc

+3-4
Original file line numberDiff line numberDiff line change
@@ -511,14 +511,14 @@ bool post_fix_result(BG_result_buf_mgr *resbuf_mgr, BG_geotype &geout,
511511
geout.set_components_no_overlapped(true);
512512
if (geout.get_ptr() == NULL) return true;
513513
if (res) {
514-
const char *resptr = geout.get_cptr() - GEOM_HEADER_SIZE;
514+
char *resptr = geout.get_cptr() - GEOM_HEADER_SIZE;
515515
size_t len = geout.get_nbytes();
516516

517517
/*
518518
The resptr buffer is now owned by resbuf_mgr and used by res, resptr
519519
will be released properly by resbuf_mgr.
520520
*/
521-
resbuf_mgr->add_buffer(const_cast<char *>(resptr));
521+
resbuf_mgr->add_buffer(resptr);
522522
/*
523523
Pass resptr as const pointer so that the memory space won't be reused
524524
by res object. Reuse is forbidden because the memory comes from BG
@@ -527,8 +527,7 @@ bool post_fix_result(BG_result_buf_mgr *resbuf_mgr, BG_geotype &geout,
527527
res->set(resptr, len + GEOM_HEADER_SIZE, &my_charset_bin);
528528

529529
// Prefix the GEOMETRY header.
530-
write_geometry_header(const_cast<char *>(resptr), geout.get_srid(),
531-
geout.get_geotype());
530+
write_geometry_header(resptr, geout.get_srid(), geout.get_geotype());
532531

533532
/*
534533
Give up ownership because the buffer may have to live longer than

Diff for: sql/mysqld.cc

+4-4
Original file line numberDiff line numberDiff line change
@@ -969,8 +969,8 @@ char *my_admin_bind_addr_str;
969969
uint mysqld_admin_port;
970970
bool listen_admin_interface_in_separate_thread;
971971
static const char *default_collation_name;
972-
char *default_storage_engine;
973-
char *default_tmp_storage_engine;
972+
const char *default_storage_engine;
973+
const char *default_tmp_storage_engine;
974974
ulonglong temptable_max_ram;
975975
bool temptable_use_mmap;
976976
static char compiled_default_collation_name[] = MYSQL_DEFAULT_COLLATION_NAME;
@@ -1282,7 +1282,7 @@ char logname_path[FN_REFLEN];
12821282
char slow_logname_path[FN_REFLEN];
12831283
char secure_file_real_path[FN_REFLEN];
12841284
Time_zone *default_tz;
1285-
char *mysql_data_home = const_cast<char *>(".");
1285+
const char *mysql_data_home = ".";
12861286
const char *mysql_real_data_home_ptr = mysql_real_data_home;
12871287
char server_version[SERVER_VERSION_LENGTH];
12881288
const char *mysqld_unix_port;
@@ -4314,7 +4314,7 @@ int init_common_variables() {
43144314

43154315
From MySQL 5.5 onwards, the default storage engine is InnoDB.
43164316
*/
4317-
default_storage_engine = const_cast<char *>("InnoDB");
4317+
default_storage_engine = "InnoDB";
43184318
default_tmp_storage_engine = default_storage_engine;
43194319

43204320
/*

Diff for: sql/mysqld.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,8 @@ extern const char *shared_memory_base_name;
220220
extern const char *mysqld_unix_port;
221221
extern char *default_tz_name;
222222
extern Time_zone *default_tz;
223-
extern char *default_storage_engine;
224-
extern char *default_tmp_storage_engine;
223+
extern const char *default_storage_engine;
224+
extern const char *default_tmp_storage_engine;
225225
extern ulonglong temptable_max_ram;
226226
extern bool temptable_use_mmap;
227227
extern bool using_udf_functions;
@@ -634,7 +634,7 @@ extern long tc_heuristic_recover;
634634
extern ulong specialflag;
635635
extern size_t mysql_data_home_len;
636636
extern const char *mysql_real_data_home_ptr;
637-
extern MYSQL_PLUGIN_IMPORT char *mysql_data_home;
637+
extern MYSQL_PLUGIN_IMPORT const char *mysql_data_home;
638638
extern "C" MYSQL_PLUGIN_IMPORT char server_version[SERVER_VERSION_LENGTH];
639639
extern MYSQL_PLUGIN_IMPORT char mysql_real_data_home[];
640640
extern char mysql_unpacked_real_data_home[];

Diff for: sql/opt_hints.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -631,8 +631,8 @@ bool Sys_var_hint::add_var(THD *thd, sys_var *sys_var, Item *sys_var_value) {
631631
}
632632
}
633633

634-
set_var *var = new (thd->mem_root) set_var(
635-
OPT_SESSION, sys_var, (const LEX_STRING *)&sys_var->name, sys_var_value);
634+
set_var *var = new (thd->mem_root)
635+
set_var(OPT_SESSION, sys_var, sys_var->name, sys_var_value);
636636
if (!var) return true;
637637

638638
Hint_set_var *hint_var = new (thd->mem_root) Hint_set_var(var);

Diff for: sql/parse_tree_helpers.cc

+3-3
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ bool find_sys_var_null_base(THD *thd, struct sys_var_with_base *tmp) {
114114
if (tmp->var == NULL)
115115
my_error(ER_UNKNOWN_SYSTEM_VARIABLE, MYF(0), tmp->base_name.str);
116116
else
117-
tmp->base_name = null_lex_str;
117+
tmp->base_name = NULL_CSTR;
118118

119119
return thd->is_error();
120120
}
@@ -160,7 +160,7 @@ bool set_system_variable(THD *thd, struct sys_var_with_base *var_with_base,
160160
}
161161

162162
set_var *var = new (thd->mem_root)
163-
set_var(var_type, var_with_base->var, &var_with_base->base_name, val);
163+
set_var(var_type, var_with_base->var, var_with_base->base_name, val);
164164
if (var == nullptr) return true;
165165

166166
return lex->var_list.push_back(var);
@@ -194,7 +194,7 @@ LEX_CSTRING make_string(THD *thd, const char *start_ptr, const char *end_ptr) {
194194
@return error status (true if error, false otherwise).
195195
*/
196196

197-
bool set_trigger_new_row(Parse_context *pc, LEX_STRING trigger_field_name,
197+
bool set_trigger_new_row(Parse_context *pc, LEX_CSTRING trigger_field_name,
198198
Item *expr_item, LEX_CSTRING expr_query) {
199199
THD *thd = pc->thd;
200200
LEX *lex = thd->lex;

Diff for: sql/parse_tree_helpers.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ bool find_sys_var_null_base(THD *thd, struct sys_var_with_base *tmp);
226226
bool set_system_variable(THD *thd, struct sys_var_with_base *tmp,
227227
enum enum_var_type var_type, Item *val);
228228
LEX_CSTRING make_string(THD *thd, const char *start_ptr, const char *end_ptr);
229-
bool set_trigger_new_row(Parse_context *pc, LEX_STRING trigger_field_name,
229+
bool set_trigger_new_row(Parse_context *pc, LEX_CSTRING trigger_field_name,
230230
Item *expr_item, LEX_CSTRING expr_query);
231231
void sp_create_assignment_lex(THD *thd, const char *option_ptr);
232232
bool sp_create_assignment_instr(THD *thd, const char *expr_end_ptr);

Diff for: sql/parse_tree_items.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ class PTI_variable_aux_3d : public Parse_tree_item {
547547
}
548548

549549
/* disallow "SELECT @@global.global.variable" */
550-
if (ident1.str && ident2.str && check_reserved_words(&ident1)) {
550+
if (ident1.str && ident2.str && check_reserved_words(ident1.str)) {
551551
error(pc, ident1_pos);
552552
return true;
553553
}

Diff for: sql/parse_tree_nodes.cc

+7-9
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ bool PT_internal_variable_name_2d::contextualize(Parse_context *pc) {
221221
LEX *lex = thd->lex;
222222
sp_head *sp = lex->sphead;
223223

224-
if (check_reserved_words(&ident1)) {
224+
if (check_reserved_words(ident1.str)) {
225225
error(pc, pos);
226226
return true;
227227
}
@@ -245,8 +245,8 @@ bool PT_internal_variable_name_2d::contextualize(Parse_context *pc) {
245245
value.var = trg_new_row_fake_var;
246246
value.base_name = ident2;
247247
} else {
248-
const LEX_STRING *domain;
249-
const LEX_STRING *variable;
248+
LEX_CSTRING *domain;
249+
LEX_CSTRING *variable;
250250
bool is_key_cache_variable = false;
251251
sys_var *tmp;
252252
if (ident2.str && is_key_cache_variable_suffix(ident2.str)) {
@@ -280,7 +280,7 @@ bool PT_internal_variable_name_2d::contextualize(Parse_context *pc) {
280280
if (is_key_cache_variable)
281281
value.base_name = *variable;
282282
else
283-
value.base_name = null_lex_str;
283+
value.base_name = NULL_CSTR;
284284
}
285285
return false;
286286
}
@@ -402,9 +402,8 @@ bool PT_option_value_no_option_type_password_for::contextualize(
402402
// Current password is specified through the REPLACE clause hence set the flag
403403
if (current_password != nullptr) user->uses_replace_clause = true;
404404

405-
var = new (thd->mem_root) set_var_password(
406-
user, const_cast<char *>(password), const_cast<char *>(current_password),
407-
retain_current_password);
405+
var = new (thd->mem_root) set_var_password(user, password, current_password,
406+
retain_current_password);
408407

409408
if (var == NULL || lex->var_list.push_back(var)) {
410409
return true; // Out of memory
@@ -439,8 +438,7 @@ bool PT_option_value_no_option_type_password::contextualize(Parse_context *pc) {
439438
if (!user) return true;
440439

441440
set_var_password *var = new (thd->mem_root) set_var_password(
442-
user, const_cast<char *>(password), const_cast<char *>(current_password),
443-
retain_current_password);
441+
user, password, current_password, retain_current_password);
444442
if (var == NULL || lex->var_list.push_back(var)) {
445443
return true; // Out of Memory
446444
}

Diff for: sql/parse_tree_nodes.h

+8-9
Original file line numberDiff line numberDiff line change
@@ -972,11 +972,10 @@ class PT_internal_variable_name : public Parse_tree_node {
972972
class PT_internal_variable_name_1d : public PT_internal_variable_name {
973973
typedef PT_internal_variable_name super;
974974

975-
LEX_STRING ident;
975+
LEX_CSTRING ident;
976976

977977
public:
978-
PT_internal_variable_name_1d(const LEX_STRING &ident_arg)
979-
: ident(ident_arg) {}
978+
PT_internal_variable_name_1d(LEX_CSTRING ident_arg) : ident(ident_arg) {}
980979

981980
bool contextualize(Parse_context *pc) override;
982981
};
@@ -991,12 +990,12 @@ class PT_internal_variable_name_2d : public PT_internal_variable_name {
991990
const POS pos;
992991

993992
private:
994-
LEX_STRING ident1;
995-
LEX_STRING ident2;
993+
LEX_CSTRING ident1;
994+
LEX_CSTRING ident2;
996995

997996
public:
998-
PT_internal_variable_name_2d(const POS &pos, const LEX_STRING &ident1_arg,
999-
const LEX_STRING &ident2_arg)
997+
PT_internal_variable_name_2d(const POS &pos, LEX_CSTRING ident1_arg,
998+
LEX_CSTRING ident2_arg)
1000999
: pos(pos), ident1(ident1_arg), ident2(ident2_arg) {}
10011000

10021001
bool contextualize(Parse_context *pc) override;
@@ -1021,7 +1020,7 @@ class PT_internal_variable_name_default : public PT_internal_variable_name {
10211020
return true;
10221021
}
10231022
value.var = tmp;
1024-
value.base_name.str = const_cast<char *>("default");
1023+
value.base_name.str = "default";
10251024
value.base_name.length = 7;
10261025
return false;
10271026
}
@@ -1343,7 +1342,7 @@ class PT_transaction_characteristic : public Parse_tree_node {
13431342
Item *item = new (pc->mem_root) Item_int(value);
13441343
if (item == NULL) return true;
13451344
set_var *var = new (thd->mem_root)
1346-
set_var(lex->option_type, find_sys_var(thd, name), &null_lex_str, item);
1345+
set_var(lex->option_type, find_sys_var(thd, name), NULL_CSTR, item);
13471346
if (var == NULL) return true;
13481347
lex->var_list.push_back(var);
13491348
return false;

Diff for: sql/parser_yystype.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ enum class enum_ha_read_modes;
7171
*/
7272
struct sys_var_with_base {
7373
sys_var *var;
74-
LEX_STRING base_name;
74+
LEX_CSTRING base_name;
7575
};
7676

7777
enum enum_drop_mode {

0 commit comments

Comments
 (0)