Skip to content

Commit eda9e56

Browse files
committed
Bug#28787272: FIX -WCAST-QUAL COMPILATION WARNINGS [noclose]
Avoid casting away constness using C-style cast. Either use const consistently or explicitly remove const with const_cast. Patch 18. Change-Id: I92ea8da5143c527b91718563888258ec41e8fe09
1 parent 758b3a7 commit eda9e56

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+564
-542
lines changed

include/my_getopt.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2002, 2018, Oracle and/or its affiliates. All rights reserved.
2+
Copyright (c) 2002, 2019, Oracle and/or its affiliates. All rights reserved.
33
44
This program is free software; you can redistribute it and/or modify
55
it under the terms of the GNU General Public License, version 2.0,
@@ -165,7 +165,7 @@ ulonglong max_of_int_range(int var_type);
165165

166166
ulonglong getopt_double2ulonglong(double);
167167
double getopt_ulonglong2double(ulonglong);
168-
int findopt(char *, uint, const struct my_option **);
168+
int findopt(const char *, uint, const struct my_option **);
169169

170170
bool is_key_cache_variable_suffix(const char *suffix);
171171

include/my_stacktrace.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
#if defined(HAVE_BACKTRACE) || defined(_WIN32)
4747
#define HAVE_STACKTRACE 1
4848
void my_init_stacktrace();
49-
void my_print_stacktrace(uchar *stack_bottom, ulong thread_stack);
49+
void my_print_stacktrace(const uchar *stack_bottom, ulong thread_stack);
5050
void my_safe_puts_stderr(const char *val, size_t max_len);
5151

5252
#ifdef _WIN32

include/sql_string.h

+1
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ class Simple_cstring {
8989
set(str_arg, length_arg);
9090
}
9191
Simple_cstring(const LEX_STRING arg) { set(arg.str, arg.length); }
92+
Simple_cstring(const LEX_CSTRING arg) { set(arg.str, arg.length); }
9293
void reset() { set(NULL, 0); }
9394
/**
9495
Set to a null-terminated string.

mysys/my_getopt.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -909,7 +909,7 @@ static int setval(const struct my_option *opts, void *value,
909909
@retval 1 Found an option
910910
*/
911911

912-
int findopt(char *optpat, uint length, const struct my_option **opt_res) {
912+
int findopt(const char *optpat, uint length, const struct my_option **opt_res) {
913913
for (const struct my_option *opt = *opt_res; opt->name; opt++)
914914
if (!getopt_compare_strings(opt->name, optpat, length) &&
915915
!opt->name[length]) {

mysys/stacktrace.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ static void my_demangle_symbols(char **addrs, int n) {
259259

260260
#endif /* HAVE_ABI_CXA_DEMANGLE */
261261

262-
void my_print_stacktrace(uchar *stack_bottom, ulong thread_stack) {
262+
void my_print_stacktrace(const uchar *stack_bottom, ulong thread_stack) {
263263
#if defined(__FreeBSD__)
264264
static char procname_buffer[2048];
265265
unw_cursor_t cursor;
@@ -409,7 +409,7 @@ static void get_symbol_path(char *path, size_t size) {
409409
#define SYMOPT_NO_PROMPTS 0
410410
#endif
411411

412-
void my_print_stacktrace(uchar *unused1, ulong unused2) {
412+
void my_print_stacktrace(const uchar *unused1, ulong unused2) {
413413
HANDLE hProcess = GetCurrentProcess();
414414
HANDLE hThread = GetCurrentThread();
415415
static IMAGEHLP_MODULE64 module = {sizeof(module)};

sql/auth/acl_table_user.cc

+13-14
Original file line numberDiff line numberDiff line change
@@ -1289,7 +1289,7 @@ bool Acl_table_user_reader::read_authentication_string(ACL_USER &user) {
12891289
user.credentials[PRIMARY_CRED].m_auth_string.length =
12901290
strlen(user.credentials[PRIMARY_CRED].m_auth_string.str);
12911291
} else {
1292-
user.credentials[PRIMARY_CRED].m_auth_string = EMPTY_STR;
1292+
user.credentials[PRIMARY_CRED].m_auth_string = EMPTY_CSTR;
12931293
}
12941294

12951295
return false;
@@ -1523,7 +1523,8 @@ bool Acl_table_user_reader::read_plugin_info(
15231523
if (plugin) {
15241524
st_mysql_auth *auth = (st_mysql_auth *)plugin_decl(plugin)->info;
15251525
if (auth->validate_authentication_string(
1526-
user.credentials[PRIMARY_CRED].m_auth_string.str,
1526+
const_cast<char *>(
1527+
user.credentials[PRIMARY_CRED].m_auth_string.str),
15271528
user.credentials[PRIMARY_CRED].m_auth_string.length)) {
15281529
LogErr(WARNING_LEVEL, ER_AUTHCACHE_USER_IGNORED_INVALID_PASSWORD,
15291530
user.user ? user.user : "",
@@ -1723,17 +1724,14 @@ bool Acl_table_user_reader::read_user_attributes(ACL_USER &user) {
17231724
if (additional_password.length()) {
17241725
user.credentials[SECOND_CRED].m_auth_string.length =
17251726
additional_password.length();
1726-
user.credentials[SECOND_CRED].m_auth_string.str =
1727-
(char *)m_mem_root.Alloc(
1728-
user.credentials[SECOND_CRED].m_auth_string.length + 1);
1729-
memcpy(user.credentials[SECOND_CRED].m_auth_string.str,
1730-
additional_password.c_str(),
1727+
char *auth_string = static_cast<char *>(m_mem_root.Alloc(
1728+
user.credentials[SECOND_CRED].m_auth_string.length + 1));
1729+
memcpy(auth_string, additional_password.c_str(),
17311730
user.credentials[SECOND_CRED].m_auth_string.length);
1732-
user.credentials[SECOND_CRED]
1733-
.m_auth_string
1734-
.str[user.credentials[SECOND_CRED].m_auth_string.length] = 0;
1731+
auth_string[user.credentials[SECOND_CRED].m_auth_string.length] = 0;
1732+
user.credentials[SECOND_CRED].m_auth_string.str = auth_string;
17351733
} else {
1736-
user.credentials[SECOND_CRED].m_auth_string = EMPTY_STR;
1734+
user.credentials[SECOND_CRED].m_auth_string = EMPTY_CSTR;
17371735
}
17381736

17391737
/* Validate the hash string. */
@@ -1743,7 +1741,8 @@ bool Acl_table_user_reader::read_user_attributes(ACL_USER &user) {
17431741
if (plugin) {
17441742
st_mysql_auth *auth = (st_mysql_auth *)plugin_decl(plugin)->info;
17451743
if (auth->validate_authentication_string(
1746-
user.credentials[SECOND_CRED].m_auth_string.str,
1744+
const_cast<char *>(
1745+
user.credentials[SECOND_CRED].m_auth_string.str),
17471746
user.credentials[SECOND_CRED].m_auth_string.length)) {
17481747
LogErr(WARNING_LEVEL, ER_AUTHCACHE_USER_IGNORED_INVALID_PASSWORD,
17491748
user.user ? user.user : "",
@@ -1755,11 +1754,11 @@ bool Acl_table_user_reader::read_user_attributes(ACL_USER &user) {
17551754
}
17561755
} else {
17571756
// user_attributes column is NULL. So use suitable defaults.
1758-
user.credentials[SECOND_CRED].m_auth_string = EMPTY_STR;
1757+
user.credentials[SECOND_CRED].m_auth_string = EMPTY_CSTR;
17591758
}
17601759
*m_restrictions = user_attributes.get_restrictions();
17611760
} else {
1762-
user.credentials[SECOND_CRED].m_auth_string = EMPTY_STR;
1761+
user.credentials[SECOND_CRED].m_auth_string = EMPTY_CSTR;
17631762
}
17641763
return false;
17651764
}

sql/auth/sql_auth_cache.cc

+3-3
Original file line numberDiff line numberDiff line change
@@ -2509,7 +2509,7 @@ void acl_update_user(const char *user, const char *host, enum SSL_type ssl_type,
25092509
/* Update auth string only when specified in ALTER/GRANT */
25102510
if (auth.str) {
25112511
if (auth.length == 0)
2512-
acl_user->credentials[PRIMARY_CRED].m_auth_string = EMPTY_STR;
2512+
acl_user->credentials[PRIMARY_CRED].m_auth_string = EMPTY_CSTR;
25132513
else
25142514
acl_user->credentials[PRIMARY_CRED].m_auth_string.str =
25152515
strmake_root(&global_acl_memory, auth.str, auth.length);
@@ -2531,7 +2531,7 @@ void acl_update_user(const char *user, const char *host, enum SSL_type ssl_type,
25312531
}
25322532
if (what_to_update.m_user_attributes &
25332533
acl_table::USER_ATTRIBUTE_DISCARD_PASSWORD) {
2534-
acl_user->credentials[SECOND_CRED].m_auth_string = EMPTY_STR;
2534+
acl_user->credentials[SECOND_CRED].m_auth_string = EMPTY_CSTR;
25352535
}
25362536
set_user_salt(acl_user);
25372537
}
@@ -2663,7 +2663,7 @@ void acl_users_add_one(THD *thd MY_ATTRIBUTE((unused)), const char *user,
26632663
acl_user.credentials[SECOND_CRED].m_auth_string.length =
26642664
second_auth.length;
26652665
} else {
2666-
acl_user.credentials[SECOND_CRED].m_auth_string = EMPTY_STR;
2666+
acl_user.credentials[SECOND_CRED].m_auth_string = EMPTY_CSTR;
26672667
}
26682668
optimize_plugin_compare_by_pointer(&acl_user.plugin);
26692669
}

sql/auth/sql_auth_cache.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ class Acl_credential {
125125
}
126126

127127
public:
128-
LEX_STRING m_auth_string;
128+
LEX_CSTRING m_auth_string;
129129
/**
130130
The salt variable is used as the password hash for
131131
native_password_authetication.

sql/auth/sql_authentication.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1732,7 +1732,7 @@ ACL_USER *decoy_user(const LEX_STRING &username, const LEX_CSTRING &hostname,
17321732
for (int i = 0; i < NUM_CREDENTIALS; ++i) {
17331733
memset(user->credentials[i].m_salt, 0, SCRAMBLE_LENGTH + 1);
17341734
user->credentials[i].m_salt_len = 0;
1735-
user->credentials[i].m_auth_string = empty_lex_str;
1735+
user->credentials[i].m_auth_string = EMPTY_CSTR;
17361736
}
17371737
return user;
17381738
}

sql/dd/info_schema/show_query_builder.cc

+13-13
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ bool Select_lex_builder::add_star_select_item() {
7676
const LEX_CSTRING star = {STRING_WITH_LEN("*")};
7777

7878
PTI_simple_ident_ident *ident_star =
79-
new (m_thd->mem_root) PTI_simple_ident_ident(*m_pos, to_lex_string(star));
79+
new (m_thd->mem_root) PTI_simple_ident_ident(*m_pos, star);
8080
if (ident_star == nullptr) return true;
8181

8282
return add_to_select_item_list(ident_star);
@@ -89,14 +89,14 @@ bool Select_lex_builder::add_star_select_item() {
8989
bool Select_lex_builder::add_select_item(const LEX_CSTRING &field_name,
9090
const LEX_CSTRING &alias) {
9191
/* ... FIELD_NAME ... */
92-
PTI_simple_ident_ident *ident_field = new (m_thd->mem_root)
93-
PTI_simple_ident_ident(*m_pos, to_lex_string(field_name));
92+
PTI_simple_ident_ident *ident_field =
93+
new (m_thd->mem_root) PTI_simple_ident_ident(*m_pos, field_name);
9494
if (ident_field == nullptr) return true;
9595

9696
/* ... FIELD_NAME as alias ... */
9797
PTI_expr_with_alias *expr;
98-
expr = new (m_thd->mem_root) PTI_expr_with_alias(
99-
*m_pos, ident_field, m_pos->cpp, to_lex_string(alias));
98+
expr = new (m_thd->mem_root)
99+
PTI_expr_with_alias(*m_pos, ident_field, m_pos->cpp, alias);
100100
if (expr == nullptr) return true;
101101

102102
return add_to_select_item_list(expr);
@@ -109,8 +109,8 @@ bool Select_lex_builder::add_select_item(const LEX_CSTRING &field_name,
109109
bool Select_lex_builder::add_select_expr(Item *select_list_item,
110110
const LEX_CSTRING &alias) {
111111
/* ... FIELD_NAME as alias ... */
112-
PTI_expr_with_alias *expr = new (m_thd->mem_root) PTI_expr_with_alias(
113-
*m_pos, select_list_item, m_pos->cpp, to_lex_string(alias));
112+
PTI_expr_with_alias *expr = new (m_thd->mem_root)
113+
PTI_expr_with_alias(*m_pos, select_list_item, m_pos->cpp, alias);
114114
if (expr == nullptr) return true;
115115

116116
return add_to_select_item_list(expr);
@@ -169,8 +169,8 @@ bool Select_lex_builder::add_from_item(PT_derived_table *dt) {
169169
Item *Select_lex_builder::prepare_like_item(const LEX_CSTRING &field_name,
170170
const String *wild) {
171171
/* ... FIELD_NAME ... */
172-
PTI_simple_ident_ident *ident_field = new (m_thd->mem_root)
173-
PTI_simple_ident_ident(*m_pos, to_lex_string(field_name));
172+
PTI_simple_ident_ident *ident_field =
173+
new (m_thd->mem_root) PTI_simple_ident_ident(*m_pos, field_name);
174174
if (ident_field == nullptr) return nullptr;
175175

176176
/* ... <value> ... */
@@ -197,8 +197,8 @@ Item *Select_lex_builder::prepare_like_item(const LEX_CSTRING &field_name,
197197
Item *Select_lex_builder::prepare_equal_item(const LEX_CSTRING &field_name,
198198
const LEX_CSTRING &value) {
199199
/* ... FIELD_NAME ... */
200-
PTI_simple_ident_ident *ident_field = new (m_thd->mem_root)
201-
PTI_simple_ident_ident(*m_pos, to_lex_string(field_name));
200+
PTI_simple_ident_ident *ident_field =
201+
new (m_thd->mem_root) PTI_simple_ident_ident(*m_pos, field_name);
202202
if (ident_field == nullptr) return nullptr;
203203

204204
/* ... <value> ... */
@@ -251,8 +251,8 @@ bool Select_lex_builder::add_order_by(const LEX_CSTRING &field_name) {
251251
}
252252

253253
/* ... FIELD_NAME ... */
254-
PTI_simple_ident_ident *ident_field = new (m_thd->mem_root)
255-
PTI_simple_ident_ident(*m_pos, to_lex_string(field_name));
254+
PTI_simple_ident_ident *ident_field =
255+
new (m_thd->mem_root) PTI_simple_ident_ident(*m_pos, field_name);
256256
if (ident_field == nullptr) return true;
257257

258258
PT_order_expr *expression =

sql/dd/upgrade_57/event.cc

+7-6
Original file line numberDiff line numberDiff line change
@@ -322,13 +322,14 @@ static bool update_event_timing_fields(THD *thd, TABLE *table,
322322
@retval >=0 Ordinal position.
323323
*/
324324

325-
static int find_string_in_array(const LEX_STRING *haystack,
326-
const LEX_STRING *needle,
325+
static int find_string_in_array(const LEX_CSTRING *haystack,
326+
const LEX_CSTRING *needle,
327327
const CHARSET_INFO *cs) {
328-
const LEX_STRING *pos;
328+
const LEX_CSTRING *pos;
329329
for (pos = haystack; pos->str; pos++) {
330-
if (!cs->coll->strnncollsp(cs, (uchar *)pos->str, pos->length,
331-
(uchar *)needle->str, needle->length)) {
330+
if (!cs->coll->strnncollsp(
331+
cs, pointer_cast<const uchar *>(pos->str), pos->length,
332+
pointer_cast<const uchar *>(needle->str), needle->length)) {
332333
return static_cast<int>(pos - haystack);
333334
}
334335
}
@@ -373,7 +374,7 @@ static bool set_status_and_interval_for_event(THD *thd, TABLE *table,
373374
int i;
374375
char buff[MAX_FIELD_WIDTH];
375376
String str(buff, sizeof(buff), &my_charset_bin);
376-
LEX_STRING tmp;
377+
LEX_CSTRING tmp;
377378

378379
table->field[ET_FIELD_TRANSIENT_INTERVAL]->val_str(&str);
379380
if (!(tmp.length = str.length())) return true;

sql/event_data_objects.cc

+5-5
Original file line numberDiff line numberDiff line change
@@ -930,7 +930,7 @@ int Event_timed::get_create_event(const THD *thd, String *buf) {
930930
buf->append(STRING_WITH_LEN(" ON SCHEDULE EVERY "));
931931
buf->append(expr_buf);
932932
buf->append(' ');
933-
const LEX_STRING *ival = &interval_type_to_name[m_interval];
933+
const LEX_CSTRING *ival = &interval_type_to_name[m_interval];
934934
buf->append(ival->str, ival->length);
935935

936936
if (!m_starts_null)
@@ -985,8 +985,8 @@ bool Event_job_data::construct_sp_sql(THD *thd, String *sp_sql) {
985985
sp_sql->set(buffer.str, buffer.length, system_charset_info);
986986
sp_sql->length(0);
987987

988-
sp_sql->append(C_STRING_WITH_LEN("CREATE "));
989-
sp_sql->append(C_STRING_WITH_LEN("PROCEDURE "));
988+
sp_sql->append(STRING_WITH_LEN("CREATE "));
989+
sp_sql->append(STRING_WITH_LEN("PROCEDURE "));
990990
/*
991991
Let's use the same name as the event name to perhaps produce a
992992
better error message in case it is a part of some parse error.
@@ -1001,7 +1001,7 @@ bool Event_job_data::construct_sp_sql(THD *thd, String *sp_sql) {
10011001
let's execute the procedure with the invoker rights to save on
10021002
resets of security contexts.
10031003
*/
1004-
sp_sql->append(C_STRING_WITH_LEN("() SQL SECURITY INVOKER "));
1004+
sp_sql->append(STRING_WITH_LEN("() SQL SECURITY INVOKER "));
10051005

10061006
sp_sql->append(m_definition.str, m_definition.length);
10071007

@@ -1223,7 +1223,7 @@ bool construct_drop_event_sql(THD *thd, String *sp_sql,
12231223
sp_sql->set(buffer.str, buffer.length, system_charset_info);
12241224
sp_sql->length(0);
12251225

1226-
ret |= sp_sql->append(C_STRING_WITH_LEN("DROP EVENT IF EXISTS"));
1226+
ret |= sp_sql->append(STRING_WITH_LEN("DROP EVENT IF EXISTS"));
12271227
append_identifier(thd, sp_sql, schema_name.str, schema_name.length);
12281228
ret |= sp_sql->append('.');
12291229
append_identifier(thd, sp_sql, event_name.str, event_name.length);

sql/event_scheduler.cc

+7-7
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,10 @@
7979

8080
extern my_thread_attr_t connection_attrib;
8181

82-
static const LEX_STRING scheduler_states_names[] = {
83-
{C_STRING_WITH_LEN("INITIALIZED")},
84-
{C_STRING_WITH_LEN("RUNNING")},
85-
{C_STRING_WITH_LEN("STOPPING")}};
82+
static const LEX_CSTRING scheduler_states_names[] = {
83+
{STRING_WITH_LEN("INITIALIZED")},
84+
{STRING_WITH_LEN("RUNNING")},
85+
{STRING_WITH_LEN("STOPPING")}};
8686

8787
struct scheduler_param {
8888
THD *thd;
@@ -212,10 +212,10 @@ void pre_init_event_thread(THD *thd) {
212212
DBUG_TRACE;
213213
thd->security_context()->set_master_access(0);
214214
thd->security_context()->cache_current_db_access(0);
215-
thd->security_context()->set_host_or_ip_ptr((char *)my_localhost,
215+
thd->security_context()->set_host_or_ip_ptr(my_localhost,
216216
strlen(my_localhost));
217217
thd->get_protocol_classic()->init_net(NULL);
218-
thd->security_context()->set_user_ptr(C_STRING_WITH_LEN("event_scheduler"));
218+
thd->security_context()->set_user_ptr(STRING_WITH_LEN("event_scheduler"));
219219
thd->get_protocol_classic()->get_net()->read_timeout = slave_net_timeout;
220220
thd->slave_thread = 0;
221221
thd->variables.option_bits |= OPTION_AUTO_IS_NULL;
@@ -477,7 +477,7 @@ bool Event_scheduler::start(int *err_no) {
477477
Therefore, assign all privileges to this thread.
478478
*/
479479
new_thd->security_context()->skip_grants();
480-
new_thd->security_context()->set_host_or_ip_ptr((char *)my_localhost,
480+
new_thd->security_context()->set_host_or_ip_ptr(my_localhost,
481481
strlen(my_localhost));
482482
new_thd->variables.transaction_read_only = false;
483483
new_thd->tx_read_only = false;

sql/handler.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -7436,7 +7436,7 @@ bool ha_show_status(THD *thd, handlerton *db_type, enum ha_stat_type stat) {
74367436
MYSQL_STORAGE_ENGINE_PLUGIN, &stat);
74377437
} else {
74387438
if (db_type->state != SHOW_OPTION_YES) {
7439-
const LEX_STRING *name = &se_plugin_array[db_type->slot]->name;
7439+
const LEX_CSTRING *name = &se_plugin_array[db_type->slot]->name;
74407440
result = stat_print(thd, name->str, name->length, "", 0, "DISABLED", 8)
74417441
? 1
74427442
: 0;

sql/item.h

+1
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,7 @@ class Name_string : public Simple_cstring {
296296
*/
297297
Name_string(const char *str, size_t length) : Simple_cstring(str, length) {}
298298
Name_string(const LEX_STRING str) : Simple_cstring(str) {}
299+
Name_string(const LEX_CSTRING str) : Simple_cstring(str) {}
299300
Name_string(const char *str, size_t length, bool is_null_terminated)
300301
: Simple_cstring() {
301302
set_or_copy(str, length, is_null_terminated);

0 commit comments

Comments
 (0)