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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 13 additions & 14 deletions
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 13 additions & 13 deletions
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 =

0 commit comments

Comments
 (0)