Skip to content

Commit 4cc4db6

Browse files
committed
Bug#35307859: Fix clang-tidy warnings related to const correctness
Resolve a large number of instances of the following clang-tidy warning: [misc-const-correctness] warning: variable 't' of type 'double' can be declared 'const' https://clang.llvm.org/extra/clang-tidy/checks/misc/const-correctness.html Local variables not being modified after initialization are now declared const. The increases type safety and prevents you from accidentally modifying something you didn’t expect would be modified. This info can also help compiler to make better code optimization decisions. Change-Id: Id478cb2898ed0332629e59912d6f295658ce3aa6
1 parent b8975e9 commit 4cc4db6

File tree

392 files changed

+4688
-4446
lines changed

Some content is hidden

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

392 files changed

+4688
-4446
lines changed

client/base/abstract_options_provider.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ void Abstract_options_provider::notify_option_name_changed(I_option *source,
146146
this->m_name_usage.erase(this->m_name_usage.find(old_name));
147147
}
148148

149-
string new_name = source->get_my_option().name;
149+
const string new_name = source->get_my_option().name;
150150

151151
// Try to find existing option with that name.
152152
map<string, I_option *>::iterator name_item =
@@ -178,15 +178,15 @@ void Abstract_options_provider::notify_option_optid_changed(I_option *source,
178178
this->m_optid_usage.erase(this->m_optid_usage.find(old_optid));
179179
}
180180

181-
uint32 new_optid = source->get_my_option().id;
181+
const uint32 new_optid = source->get_my_option().id;
182182

183183
// Try to find existing option with that optid.
184184
map<uint32, I_option *>::iterator optid_item =
185185
this->m_optid_usage.find(new_optid);
186186

187187
// Report error if already used.
188188
if (optid_item != this->m_optid_usage.end()) {
189-
string name = source->get_my_option().name;
189+
const string name = source->get_my_option().name;
190190

191191
std::cerr << "Cannot register new option \"" << name
192192
<< "\" as it collides with existing one with following name \""

client/base/abstract_program.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ void Abstract_program::run(int argc, char **argv) {
6969
Message_type_error));
7070
my_getopt_use_args_separator = false;
7171

72-
int ho_error = handle_options(&argc, &argv, this->get_options_array(),
73-
Abstract_program::callback_option_parsed);
72+
const int ho_error = handle_options(&argc, &argv, this->get_options_array(),
73+
Abstract_program::callback_option_parsed);
7474
if (ho_error != 0) {
7575
this->error(Message_data(ho_error, "Error during handling options",
7676
Message_type_error));

client/base/help_options.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ void Mysql::Tools::Base::Options::Help_options::print_usage() {
8080
copyright = ORACLE_WELCOME_COPYRIGHT_NOTICE(COPYRIGHT_NOTICE_CURRENT_YEAR);
8181
} else {
8282
#define FIRST_YEAR_CONSTANT "$first_year$"
83-
string first_year_constant_str = FIRST_YEAR_CONSTANT;
83+
const string first_year_constant_str = FIRST_YEAR_CONSTANT;
8484

8585
copyright = ORACLE_WELCOME_COPYRIGHT_NOTICE(FIRST_YEAR_CONSTANT);
8686
copyright =

client/base/mysql_query_runner.cc

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ int64 Mysql_query_runner::run_query(
9393
std::string query, std::function<int64(const Row &)> *result_callback) {
9494
Mysql_query_runner copy(*this);
9595
copy.add_result_callback(result_callback);
96-
int64 result = copy.run_query(query);
96+
const int64 result = copy.run_query(query);
9797
delete result_callback;
9898
copy.m_result_callbacks.clear();
9999
return result;
@@ -113,7 +113,7 @@ int64 Mysql_query_runner::run_query(std::string query) {
113113
Message_type_error);
114114
return this->report_message(message);
115115
}
116-
uint64 result = this->run_query_unguarded(query);
116+
const uint64 result = this->run_query_unguarded(query);
117117
*m_is_processing = false;
118118

119119
return result;
@@ -140,13 +140,13 @@ int64 Mysql_query_runner::run_query_unguarded(string query) {
140140
}
141141
}
142142

143-
unsigned int columns = mysql_field_count(m_connection);
143+
const unsigned int columns = mysql_field_count(m_connection);
144144
Row *processed_row = new Row(results, columns, row);
145145

146146
vector<std::function<int64(const Row &)> *>::reverse_iterator it;
147147
for (it = m_result_callbacks.rbegin(); it != m_result_callbacks.rend();
148148
++it) {
149-
int64 callback_result = (**it)(*processed_row);
149+
const int64 callback_result = (**it)(*processed_row);
150150
if (callback_result != 0) {
151151
mysql_free_result(results);
152152
return callback_result;
@@ -176,7 +176,7 @@ int64 Mysql_query_runner::run_query_unguarded(string query) {
176176
break;
177177
}
178178

179-
unsigned int columns = mysql_field_count(m_connection);
179+
const unsigned int columns = mysql_field_count(m_connection);
180180
Row *processed_row = new Row(results, columns, row);
181181

182182
Warning_data warning(
@@ -199,7 +199,7 @@ int64 Mysql_query_runner::report_mysql_error() {
199199
int64 Mysql_query_runner::report_message(Message_data &message) {
200200
for (auto it = m_message_callbacks.rbegin(); it != m_message_callbacks.rend();
201201
it++) {
202-
int64 callback_result = (*it->first)(message);
202+
const int64 callback_result = (*it->first)(message);
203203
if (callback_result < 0) {
204204
return 0;
205205
} else if (callback_result != 0) {
@@ -263,11 +263,11 @@ void Mysql_query_runner::append_escape_string(std::string *destination_string,
263263
void Mysql_query_runner::append_escape_string(std::string *destination_string,
264264
const char *original,
265265
size_t original_length) {
266-
size_t start_lenght = destination_string->size();
267-
size_t required_capacity = start_lenght + original_length * 2 + 1;
266+
const size_t start_lenght = destination_string->size();
267+
const size_t required_capacity = start_lenght + original_length * 2 + 1;
268268
destination_string->resize(required_capacity);
269269

270-
int length = mysql_real_escape_string_quote(
270+
const int length = mysql_real_escape_string_quote(
271271
m_connection, &((*destination_string)[0]) + start_lenght, original,
272272
(ulong)original_length, '"');
273273
destination_string->resize(start_lenght + length);
@@ -276,12 +276,12 @@ void Mysql_query_runner::append_escape_string(std::string *destination_string,
276276
void Mysql_query_runner::append_hex_string(std::string *destination_string,
277277
const char *original,
278278
size_t original_length) {
279-
size_t start_lenght = destination_string->size();
280-
size_t required_capacity = start_lenght + original_length * 2 + 1;
279+
const size_t start_lenght = destination_string->size();
280+
const size_t required_capacity = start_lenght + original_length * 2 + 1;
281281
destination_string->resize(required_capacity);
282282

283-
int length = mysql_hex_string(&((*destination_string)[0]) + start_lenght,
284-
original, original_length);
283+
const int length = mysql_hex_string(
284+
&((*destination_string)[0]) + start_lenght, original, original_length);
285285
destination_string->resize(start_lenght + length);
286286
}
287287

@@ -351,7 +351,7 @@ const char *Mysql_query_runner::Row::get_buffer(std::size_t index,
351351
start = m_buffer_starts[start_index];
352352
}
353353

354-
std::size_t end = m_buffer_starts[index + 1];
354+
const std::size_t end = m_buffer_starts[index + 1];
355355
length = (end - start - 1);
356356
return &m_buffer[start];
357357
}

client/check/mysqlcheck.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ static void usage(void) {
304304
extern "C" {
305305
static bool get_one_option(int optid, const struct my_option *opt,
306306
char *argument) {
307-
int orig_what_to_do = what_to_do;
307+
const int orig_what_to_do = what_to_do;
308308

309309
switch (optid) {
310310
case 'a':
@@ -395,7 +395,7 @@ static int get_options(int *argc, char ***argv, MEM_ROOT *alloc) {
395395
my_getopt_use_args_separator = false;
396396

397397
if (!what_to_do) {
398-
size_t pnlen = strlen(my_progname);
398+
const size_t pnlen = strlen(my_progname);
399399

400400
if (pnlen < 6) /* name too short */
401401
what_to_do = DO_CHECK;

client/check/mysqlcheck_core.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,8 +280,8 @@ static void print_result() {
280280
prev_alter[0] = 0;
281281

282282
while ((row = mysql_fetch_row(res))) {
283-
int changed = strcmp(prev, row[0]);
284-
bool status = !strcmp(row[2], "status");
283+
const int changed = strcmp(prev, row[0]);
284+
const bool status = !strcmp(row[2], "status");
285285

286286
if (status) {
287287
/*

client/client_query_attributes.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ bool client_query_attributes::push_param(const char *name, const char *value) {
3434
if (count >= max_count) return true;
3535
names[count] = my_strdup(PSI_NOT_INSTRUMENTED, name, MYF(0));
3636
memset(&values[count], 0, sizeof(MYSQL_BIND));
37-
unsigned val_len = strlen(value);
37+
const unsigned val_len = strlen(value);
3838
values[count].buffer = my_malloc(PSI_NOT_INSTRUMENTED, val_len + 1, MYF(0));
3939
if (val_len) memcpy(values[count].buffer, value, val_len);
4040
((unsigned char *)values[count].buffer)[val_len] = 0;
@@ -47,7 +47,7 @@ bool client_query_attributes::push_param(const char *name, const char *value) {
4747
int client_query_attributes::set_params(MYSQL *mysql) {
4848
if (count == 0) return 0;
4949

50-
int rc = mysql_bind_param(mysql, count, values, names);
50+
const int rc = mysql_bind_param(mysql, count, values, names);
5151
return rc;
5252
}
5353

client/json_binlog_main.cc

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,28 +34,28 @@
3434
int main() {
3535
json_binary::Value value = json_binary::parse_binary(nullptr, 0);
3636

37-
bool is_valid = value.is_valid();
38-
json_binary::Value::enum_type enum_type = value.type();
37+
const bool is_valid = value.is_valid();
38+
const json_binary::Value::enum_type enum_type = value.type();
3939

4040
value = json_binary::Value(json_binary::Value::OBJECT, nullptr, 0, 1, false);
4141

42-
json_binary::Value elt1 = value.element(1);
43-
json_binary::Value key1 = value.key(1);
42+
const json_binary::Value elt1 = value.element(1);
43+
const json_binary::Value key1 = value.key(1);
4444

45-
size_t sz1 = value.lookup_index("foo", 3);
46-
size_t sz2 = value.lookup_index(std::string("foo"));
45+
const size_t sz1 = value.lookup_index("foo", 3);
46+
const size_t sz2 = value.lookup_index(std::string("foo"));
4747

48-
bool has_space = value.has_space(0, 0, nullptr);
48+
const bool has_space = value.has_space(0, 0, nullptr);
4949

50-
json_binary::Value null_value =
50+
const json_binary::Value null_value =
5151
json_binary::Value(json_binary::Value::LITERAL_NULL);
5252

53-
json_binary::Value int_value =
53+
const json_binary::Value int_value =
5454
json_binary::Value(json_binary::Value::INT, 42);
5555

56-
json_binary::Value double_value = json_binary::Value(0.0);
56+
const json_binary::Value double_value = json_binary::Value(0.0);
5757

58-
json_binary::Value string_value = json_binary::Value("foo", 3);
58+
const json_binary::Value string_value = json_binary::Value("foo", 3);
5959

6060
std::string string_buf;
6161
string_value.to_std_string(&string_buf, [] { assert(false); });

client/json_client_library_main.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ int main() {
4343

4444
// Make sure Json_wrapper::seek is visible
4545
Json_wrapper_vector hits(PSI_NOT_INSTRUMENTED);
46-
bool need_only_one{false};
46+
const bool need_only_one{false};
4747
const char *json_path = R"($**."512")";
4848
Json_path path(PSI_NOT_INSTRUMENTED);
4949
size_t bad_index;
@@ -62,15 +62,15 @@ int main() {
6262

6363
// Make sure Json_dom::parse is visible and error handling works
6464
{
65-
std::string json{"[{\"key\":123},146]"};
65+
const std::string json{"[{\"key\":123},146]"};
6666
Json_dom_ptr dom(Json_dom::parse(
6767
json.c_str(), json.length(),
6868
[](const char *, size_t) { assert(false); }, [] { assert(false); }));
6969
if (dom != nullptr) std::cout << "1. success" << std::endl;
7070
}
7171

7272
{
73-
std::string json{
73+
const std::string json{
7474
"[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[["
7575
R"([[[[[[[[[[[[[[[[[[[[[[[[[[[[[[{"key":123}]]]]]]]]]]]]]]]]]]]]]]]]]])"
7676
"]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]"
@@ -86,7 +86,7 @@ int main() {
8686
}
8787

8888
{
89-
std::string json{"[&&"};
89+
const std::string json{"[&&"};
9090
Json_dom_ptr dom(Json_dom::parse(
9191
json.c_str(), json.length(),
9292
[](const char *err_mesg, size_t err_code) {

client/logger.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ using namespace std;
3333

3434
ostream &operator<<(ostream &os, const Datetime &) {
3535
const char format[] = "%Y-%m-%d %X";
36-
time_t t(time(nullptr));
37-
tm tm(*localtime(&t));
36+
const time_t t(time(nullptr));
37+
const tm tm(*localtime(&t));
3838

3939
const size_t date_length{50};
40-
std::unique_ptr<char[]> date{new char[date_length]};
40+
const std::unique_ptr<char[]> date{new char[date_length]};
4141
strftime(date.get(), date_length, format, &tm);
4242

4343
os << date.get() << " ";
@@ -49,7 +49,7 @@ ostream &operator<<(ostream &os, const Gen_spaces &gen) {
4949
}
5050

5151
int Log::Log_buff::sync() {
52-
string sout(str());
52+
const string sout(str());
5353
if (m_enabled && sout.length() > 0) {
5454
m_os << Datetime() << "[" << m_logc << "]"
5555
<< Gen_spaces(8 - m_logc.length()) << sout;

0 commit comments

Comments
 (0)