Skip to content

Commit f89ed74

Browse files
committed
Bug#33957087: Fix clang-tidy, cppcheck warnings
The scope of this bug is to fix a selection of clang-tidy and cppcheck warnings related to the MySQL server code. In general, the aim is to fix large number of non-controversial, easy to fix issues (no major code refactoring needed), focusing on server general code. Approved by: Marc Alff <marc.alff@oracle.com> Approved by: Harin Vadodaria <harin.vadodaria@oracle.com> RB: 27760 Change-Id: I3645ba62e62b2c7c3c312507471b18cbe8e9eec9
1 parent ac8ae0d commit f89ed74

Some content is hidden

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

50 files changed

+322
-388
lines changed

client/base/abstract_options_provider.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2001, 2021, Oracle and/or its affiliates.
2+
Copyright (c) 2001, 2022, Oracle and/or its affiliates.
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,
@@ -114,7 +114,7 @@ vector<my_option> Abstract_options_provider::generate_options() {
114114

115115
vector<my_option> res;
116116
for (vector<I_option *>::iterator it = this->m_options_created.begin();
117-
it != this->m_options_created.end(); it++) {
117+
it != this->m_options_created.end(); ++it) {
118118
res.push_back((*it)->get_my_option());
119119
}
120120

@@ -128,7 +128,7 @@ Abstract_options_provider::Abstract_options_provider()
128128

129129
Abstract_options_provider::~Abstract_options_provider() {
130130
for (vector<I_option *>::iterator it = this->m_options_created.begin();
131-
it != this->m_options_created.end(); it++) {
131+
it != this->m_options_created.end(); ++it) {
132132
delete *it;
133133
}
134134
}

client/base/composite_options_provider.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2001, 2021, Oracle and/or its affiliates.
2+
Copyright (c) 2001, 2022, Oracle and/or its affiliates.
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,
@@ -63,7 +63,7 @@ void Composite_options_provider::add_provider(
6363
void Composite_options_provider::options_parsed() {
6464
vector<I_options_provider *>::iterator it;
6565
for (it = this->m_options_providers.begin();
66-
it != this->m_options_providers.end(); it++) {
66+
it != this->m_options_providers.end(); ++it) {
6767
(*it)->options_parsed();
6868
}
6969
}
@@ -74,7 +74,7 @@ vector<my_option> Composite_options_provider::generate_options() {
7474
// Add options for all children providers.
7575
vector<I_options_provider *>::iterator it;
7676
for (it = this->m_options_providers.begin();
77-
it != this->m_options_providers.end(); it++) {
77+
it != this->m_options_providers.end(); ++it) {
7878
vector<my_option> new_options = (*it)->generate_options();
7979
result.insert(result.end(), new_options.begin(), new_options.end());
8080
}

client/base/mysql_query_runner.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2014, 2021, Oracle and/or its affiliates.
2+
Copyright (c) 2014, 2022, Oracle and/or its affiliates.
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,
@@ -145,7 +145,7 @@ int64 Mysql_query_runner::run_query_unguarded(string query) {
145145

146146
vector<std::function<int64(const Row &)> *>::reverse_iterator it;
147147
for (it = m_result_callbacks.rbegin(); it != m_result_callbacks.rend();
148-
it++) {
148+
++it) {
149149
int64 callback_result = (**it)(*processed_row);
150150
if (callback_result != 0) {
151151
mysql_free_result(results);
@@ -289,7 +289,7 @@ void Mysql_query_runner::cleanup_result(
289289
std::vector<const Mysql_query_runner::Row *> *result) {
290290
for (vector<const Mysql_query_runner::Row *>::const_iterator it =
291291
result->begin();
292-
it != result->end(); it++) {
292+
it != result->end(); ++it) {
293293
delete *it;
294294
}
295295
result->clear();

client/dump/mysql_object_reader.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2015, 2021, Oracle and/or its affiliates.
2+
Copyright (c) 2015, 2022, Oracle and/or its affiliates.
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,
@@ -86,7 +86,6 @@ void Mysql_object_reader::read_table_rows_task(
8686
Table *table = table_rows_dump_task->get_related_table();
8787

8888
std::vector<const Mysql::Tools::Base::Mysql_query_runner::Row *> columns;
89-
std::vector<std::string> field_names;
9089

9190
runner->run_query_store(
9291
"SELECT `COLUMN_NAME`, `EXTRA` FROM " +

client/dump/mysqldump_tool_chain_maker.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2015, 2021, Oracle and/or its affiliates.
2+
Copyright (c) 2015, 2022, Oracle and/or its affiliates.
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,
@@ -163,7 +163,7 @@ I_object_reader *Mysqldump_tool_chain_maker::create_chain(
163163

164164
void Mysqldump_tool_chain_maker::stop_queues() {
165165
std::map<int, Object_queue *>::const_iterator iter;
166-
for (iter = m_object_queues.begin(); iter != m_object_queues.end(); iter++) {
166+
for (iter = m_object_queues.begin(); iter != m_object_queues.end(); ++iter) {
167167
iter->second->stop_queue();
168168
}
169169
}

client/dump/object_filter.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2015, 2021, Oracle and/or its affiliates.
2+
Copyright (c) 2015, 2022, Oracle and/or its affiliates.
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,
@@ -55,12 +55,12 @@ std::string parse_inclusion_string(
5555
const separator_t *sep = is_user_object ? &sep_user : &sep_object;
5656

5757
tokenizer_t outer_tok(val, sep_csl);
58-
for (titerator_t it = outer_tok.begin(); it != outer_tok.end(); it++) {
58+
for (titerator_t it = outer_tok.begin(); it != outer_tok.end(); ++it) {
5959
std::string elt = *it;
6060
boost::trim(elt);
6161
tokenizer_t itok(elt, *sep);
6262
std::vector<std::string> object_parts;
63-
for (titerator_t iit = itok.begin(); iit != itok.end(); iit++) {
63+
for (titerator_t iit = itok.begin(); iit != itok.end(); ++iit) {
6464
std::string s = *iit;
6565
boost::trim(s);
6666
if (s.length() == 0)

client/dump/sql_formatter.cc

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,8 @@ void Sql_formatter::format_row_group(Row_group_dump_task *row_group) {
141141
else if (column_length == 0)
142142
row_string += "''";
143143
else if (row_group->m_fields[column].get_additional_flags() & NUM_FLAG) {
144-
if (column_length >= 1 &&
145-
(my_isalpha(charset_info, column_data[0]) ||
144+
/* column_length is guaranteed to be >= 1 here */
145+
if ((my_isalpha(charset_info, column_data[0]) ||
146146
(column_length >= 2 && column_data[0] == '-' &&
147147
my_isalpha(charset_info, column_data[1])))) {
148148
row_string += "NULL";
@@ -224,12 +224,10 @@ void Sql_formatter::format_table_definition(
224224
mysql.innodb_index_stats tables
225225
*/
226226
if (innodb_stats_tables(table->get_schema(), table->get_name())) return;
227-
bool use_added = false;
228227
if (m_options->m_drop_table)
229228
this->append_output("DROP TABLE IF EXISTS " +
230229
this->get_quoted_object_full_name(table) + ";\n");
231-
if (m_options->m_deffer_table_indexes == 0 && !use_added) {
232-
use_added = true;
230+
if (m_options->m_deffer_table_indexes == 0) {
233231
this->append_output("USE " + this->quote_name(table->get_schema()) + ";\n");
234232
}
235233
if (!m_options->m_suppress_create_table)

include/sslopt-vars.h

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -101,36 +101,36 @@ static inline int set_client_ssl_options(MYSQL *mysql) {
101101
if (!fi) {
102102
fprintf(stderr, "Error: Can't open the ssl session data file.\n");
103103
return 1;
104-
} else {
105-
long file_length = sizeof(buff) - 1;
106-
if (0 == fseek(fi, 0, SEEK_END)) {
107-
file_length = ftell(fi);
108-
if (file_length > 0)
109-
file_length = std::min(file_length, 65536L);
110-
else
111-
file_length = sizeof(buff) - 1;
112-
fseek(fi, 0, SEEK_SET);
113-
}
114-
if (file_length > (long)(sizeof(buff) - 1)) {
115-
bufptr = (char *)malloc(file_length + 1);
116-
if (bufptr)
117-
bufptr[file_length] = 0;
118-
else {
119-
bufptr = &buff[0];
120-
file_length = sizeof(buff) - 1;
121-
}
122-
}
123-
read = fread(bufptr, 1, file_length, fi);
124-
if (!read) {
125-
fprintf(stderr, "Error: Can't read the ssl session data file.\n");
126-
fclose(fi);
127-
if (bufptr != &buff[0]) free(bufptr);
128-
return 1;
104+
}
105+
long file_length = sizeof(buff) - 1;
106+
if (0 == fseek(fi, 0, SEEK_END)) {
107+
file_length = ftell(fi);
108+
if (file_length > 0)
109+
file_length = std::min(file_length, 65536L);
110+
else
111+
file_length = sizeof(buff) - 1;
112+
fseek(fi, 0, SEEK_SET);
113+
}
114+
if (file_length > (long)(sizeof(buff) - 1)) {
115+
bufptr = (char *)malloc(file_length + 1);
116+
if (bufptr)
117+
bufptr[file_length] = 0;
118+
else {
119+
bufptr = &buff[0];
120+
file_length = sizeof(buff) - 1;
129121
}
130-
assert(read <= (size_t)file_length);
131-
bufptr[read] = 0;
122+
}
123+
read = fread(bufptr, 1, file_length, fi);
124+
if (!read) {
125+
fprintf(stderr, "Error: Can't read the ssl session data file.\n");
132126
fclose(fi);
127+
if (bufptr != &buff[0]) free(bufptr);
128+
return 1;
133129
}
130+
assert(read <= (size_t)file_length);
131+
bufptr[read] = 0;
132+
fclose(fi);
133+
134134
int ret = 0;
135135
if (read) ret = mysql_options(mysql, MYSQL_OPT_SSL_SESSION_DATA, buff);
136136
if (bufptr != &buff[0]) free(bufptr);
@@ -146,8 +146,8 @@ inline static bool ssl_client_check_post_connect_ssl_setup(
146146
report_error(
147147
"--ssl-session-data specified but the session was not reused.");
148148
return true;
149-
} else
150-
return false;
149+
}
150+
return false;
151151
}
152152

153153
#define SSL_SET_OPTIONS(mysql) set_client_ssl_options(mysql)

mysys/my_winfile.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2008, 2021, Oracle and/or its affiliates.
1+
/* Copyright (c) 2008, 2022, Oracle and/or its affiliates.
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,
@@ -148,7 +148,7 @@ int ToDescr(size_t hi) { return hi + MY_FILE_MIN; }
148148
bool IsValidIndex(size_t hi) {
149149
const HandleInfoVector &hiv = *hivp;
150150
mysql_mutex_assert_owner(&THR_LOCK_open);
151-
return (hi >= 0 && hi < hiv.size());
151+
return (hi > 0 && hi < hiv.size());
152152
}
153153

154154
HandleInfo GetHandleInfo(File fd) {

plugin/keyring/common/keys_iterator.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2017, 2021, Oracle and/or its affiliates.
1+
/* Copyright (c) 2017, 2022, Oracle and/or its affiliates.
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,
@@ -63,7 +63,7 @@ bool Keys_iterator::get_key(Key_metadata **km) {
6363
key_meta->user = key_metadata_list_iterator->user;
6464
*km = key_meta.release();
6565
}
66-
key_metadata_list_iterator++;
66+
++key_metadata_list_iterator;
6767
return false;
6868
}
6969

plugin/pfs_table_plugin/pfs_example_machines_by_emp_by_mtype.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2017, 2021, Oracle and/or its affiliates.
1+
/* Copyright (c) 2017, 2022, Oracle and/or its affiliates.
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,
@@ -100,7 +100,7 @@ int m_by_emp_by_mtype_rnd_next(PSI_table_handle *handle) {
100100
/* Make current row */
101101
make_record(&h->current_row, e_record, m_record);
102102
}
103-
it++;
103+
++it;
104104
}
105105
/* If a record was formed */
106106
if (h->current_row.m_exist) {

sql/opt_explain_json.cc

Lines changed: 17 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -771,19 +771,15 @@ class table_with_where_and_derived : public table_base_ctx {
771771
}
772772

773773
bool format_derived(Opt_trace_context *json) override {
774-
if (derived_from.elements == 0)
775-
return false;
776-
else if (derived_from.elements == 1)
777-
return derived_from.head()->format(json);
778-
else {
779-
Opt_trace_array loops(json, K_NESTED_LOOP);
774+
if (derived_from.elements == 0) return false;
775+
if (derived_from.elements == 1) return derived_from.head()->format(json);
776+
Opt_trace_array loops(json, K_NESTED_LOOP);
780777

781-
List_iterator<context> it(derived_from);
782-
context *c;
783-
while ((c = it++)) {
784-
Opt_trace_object anonymous_wrapper(json);
785-
if (c->format(json)) return true;
786-
}
778+
List_iterator<context> it(derived_from);
779+
context *c;
780+
while ((c = it++)) {
781+
Opt_trace_object anonymous_wrapper(json);
782+
if (c->format(json)) return true;
787783
}
788784
return false;
789785
}
@@ -1002,8 +998,7 @@ class simple_sort_with_subqueries_ctx : public simple_sort_ctx {
1002998
subquery_ctx *ctx) override {
1003999
if (subquery_type != subquery_type_arg)
10041000
return simple_sort_ctx::add_subquery(subquery_type_arg, ctx);
1005-
else
1006-
return subqueries.push_back(ctx);
1001+
return subqueries.push_back(ctx);
10071002
}
10081003

10091004
private:
@@ -1154,9 +1149,7 @@ class sort_with_subqueries_ctx : public sort_ctx {
11541149
subquery_ctx *ctx) override {
11551150
if (subquery_type_arg != subquery_type)
11561151
return sort_ctx::add_subquery(subquery_type_arg, ctx);
1157-
else
1158-
return subqueries.push_back(ctx);
1159-
return false;
1152+
return subqueries.push_back(ctx);
11601153
}
11611154

11621155
private:
@@ -1247,10 +1240,8 @@ class window_ctx : public join_ctx {
12471240
bool join_ctx::find_and_set_derived(context *subquery) {
12481241
assert(subquery->id() != 0);
12491242

1250-
if (sort)
1251-
return sort->find_and_set_derived(subquery);
1252-
else if (window)
1253-
return window->find_and_set_derived(subquery);
1243+
if (sort) return sort->find_and_set_derived(subquery);
1244+
if (window) return window->find_and_set_derived(subquery);
12541245

12551246
List_iterator<joinable_ctx> it(join_tabs);
12561247
joinable_ctx *t;
@@ -1262,10 +1253,8 @@ bool join_ctx::find_and_set_derived(context *subquery) {
12621253

12631254
bool join_ctx::add_subquery(subquery_list_enum subquery_type,
12641255
subquery_ctx *ctx) {
1265-
if (sort)
1266-
return sort->add_subquery(subquery_type, ctx);
1267-
else if (window)
1268-
return window->add_subquery(subquery_type, ctx);
1256+
if (sort) return sort->add_subquery(subquery_type, ctx);
1257+
if (window) return window->add_subquery(subquery_type, ctx);
12691258

12701259
if (subquery_type > SQ_toplevel) {
12711260
List_iterator<joinable_ctx> it(join_tabs);
@@ -1370,7 +1359,7 @@ bool union_result_ctx::format_body(Opt_trace_context *json,
13701359
return true; /* purecov: inspected */
13711360

13721361
if (message) {
1373-
message_ctx *msg = (message_ctx *)message;
1362+
auto *msg = (message_ctx *)message;
13741363
obj->add_alnum(K_MESSAGE, msg->entry()->col_message.str);
13751364
}
13761365

@@ -1424,10 +1413,8 @@ bool join_ctx::dependent() {
14241413

14251414
int join_ctx::add_where_subquery(subquery_ctx *ctx,
14261415
Query_expression *subquery) {
1427-
if (sort)
1428-
return sort->join_ctx::add_where_subquery(ctx, subquery);
1429-
else if (window)
1430-
return window->join_ctx::add_where_subquery(ctx, subquery);
1416+
if (sort) return sort->join_ctx::add_where_subquery(ctx, subquery);
1417+
if (window) return window->join_ctx::add_where_subquery(ctx, subquery);
14311418

14321419
List_iterator<joinable_ctx> it(join_tabs);
14331420
joinable_ctx *j;

sql/opt_hints.cc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -353,13 +353,12 @@ static table_map get_other_dep(opt_hints_enum type, table_map hint_tab_map,
353353
case JOIN_PREFIX_HINT_ENUM:
354354
if (hint_tab_map & table_map) // Hint table: No additional dependencies
355355
return 0;
356-
else // Other tables: depend on all hint tables
357-
return hint_tab_map;
356+
// Other tables: depend on all hint tables
357+
return hint_tab_map;
358358
case JOIN_SUFFIX_HINT_ENUM:
359359
if (hint_tab_map & table_map) // Hint table: depends on all other tables
360360
return ~hint_tab_map;
361-
else
362-
return 0;
361+
return 0;
363362
case JOIN_ORDER_HINT_ENUM:
364363
return 0; // No additional dependencies
365364
default:
@@ -866,8 +865,9 @@ static bool get_hint_state(Opt_hints *hint, Opt_hints *parent_hint,
866865
if (hint && hint->is_specified(type_arg)) {
867866
*ret_val = hint->get_switch(type_arg);
868867
return true;
869-
} else if (opt_hint_info[type_arg].check_upper_lvl &&
870-
parent_hint->is_specified(type_arg)) {
868+
}
869+
if (opt_hint_info[type_arg].check_upper_lvl &&
870+
parent_hint->is_specified(type_arg)) {
871871
*ret_val = parent_hint->get_switch(type_arg);
872872
return true;
873873
}

0 commit comments

Comments
 (0)