Skip to content

Commit 3ec803a

Browse files
author
Steinar H. Gunderson
committed
Bug #30163412: RUN CLANG-TIDY MODERNIZE-USE-BOOL-LITERALS
This is the first cross-cutting, large-scale clang-tidy fix. It runs the “modernize-use-bool-literal” fixit over all source code compiled in a fairly full-featured MySQL build, changing integral literals to bool literals when used in a boolean context. A typical example would be: - print_comment(sql_file, 0, "-- Dump completed on %s\n", time_str); + print_comment(sql_file, false, "-- Dump completed on %s\n", time_str); as the second argument to print_comment() is “bool is_error”. Converting 0 and 1 literals to false and true makes code easier to read by increasing self-documentation, makes type and argument order mistakes more difficult, enable compiler warnings when nonsensical operations are attempted (such as multiplying bools), and reduces noise from IDEs and other tools that check clang-tidy warnings. Change-Id: I8070dc592cd0341993d2b4261a3949b71ac5e916
1 parent b764675 commit 3ec803a

File tree

347 files changed

+4802
-4711
lines changed

Some content is hidden

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

347 files changed

+4802
-4711
lines changed

client/base/abstract_program.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved.
2+
Copyright (c) 2014, 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,
@@ -44,7 +44,7 @@ bool Abstract_program::callback_option_parsed(int, const struct my_option *opt,
4444
if (option != NULL) {
4545
option->call_callbacks(argument);
4646
}
47-
return 0;
47+
return false;
4848
}
4949

5050
const string Abstract_program::get_name() { return this->m_name; }

client/base/debug_options.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved.
2+
Copyright (c) 2014, 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,
@@ -82,7 +82,7 @@ void Debug_options::debug_option_callback(
8282
if (this->m_dbug_option.has_value()) {
8383
DBUG_PUSH(this->m_dbug_option.value().c_str());
8484
}
85-
this->m_debug_check_flag = 1;
85+
this->m_debug_check_flag = true;
8686
}
8787

8888
void Debug_options::options_parsed() {

client/base/ssl_options.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ bool Mysql_connection_options::Ssl_options::apply_for_connection(
9494
MYSQL *connection) {
9595
if (SSL_SET_OPTIONS(connection)) {
9696
std::cerr << SSL_SET_OPTIONS_ERROR;
97-
return 1;
97+
return true;
9898
}
99-
return 0;
99+
return false;
100100
}

client/check/mysqlcheck.cc

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,17 @@ using std::vector;
5353
#define EX_MYSQLERR 2
5454

5555
static MYSQL mysql_connection, *sock = 0;
56-
static bool opt_alldbs = 0, opt_check_only_changed = 0, opt_extended = 0,
57-
opt_compress = 0, opt_databases = 0, opt_fast = 0,
58-
opt_medium_check = 0, opt_quick = 0, opt_all_in_1 = 0,
59-
opt_silent = 0, opt_auto_repair = 0, ignore_errors = 0,
60-
tty_password = 0, opt_frm = 0, debug_info_flag = 0,
61-
debug_check_flag = 0, opt_fix_table_names = 0, opt_fix_db_names = 0,
62-
opt_upgrade = 0, opt_write_binlog = 1;
56+
static bool opt_alldbs = false, opt_check_only_changed = false,
57+
opt_extended = false, opt_compress = false, opt_databases = false,
58+
opt_fast = false, opt_medium_check = false, opt_quick = false,
59+
opt_all_in_1 = false, opt_silent = false, opt_auto_repair = false,
60+
ignore_errors = false, tty_password = false, opt_frm = false,
61+
debug_info_flag = false, debug_check_flag = false,
62+
opt_fix_table_names = false, opt_fix_db_names = false,
63+
opt_upgrade = false, opt_write_binlog = true;
6364
static uint verbose = 0, opt_mysql_port = 0;
6465
static uint opt_enable_cleartext_plugin = 0;
65-
static bool using_opt_enable_cleartext_plugin = 0;
66+
static bool using_opt_enable_cleartext_plugin = false;
6667
static int my_end_arg;
6768
static char *opt_mysql_unix_port = 0;
6869
static char *opt_password = 0, *current_user = 0, *current_host = 0;
@@ -296,15 +297,15 @@ static bool get_one_option(int optid, const struct my_option *opt,
296297
break;
297298
case 'C':
298299
what_to_do = DO_CHECK;
299-
opt_check_only_changed = 1;
300+
opt_check_only_changed = true;
300301
break;
301302
case 'I': /* Fall through */
302303
case '?':
303304
usage();
304305
exit(0);
305306
case 'm':
306307
what_to_do = DO_CHECK;
307-
opt_medium_check = 1;
308+
opt_medium_check = true;
308309
break;
309310
case 'o':
310311
what_to_do = DO_OPTIMIZE;
@@ -323,16 +324,16 @@ static bool get_one_option(int optid, const struct my_option *opt,
323324
opt_password = my_strdup(PSI_NOT_INSTRUMENTED, argument, MYF(MY_FAE));
324325
while (*argument) *argument++ = 'x'; /* Destroy argument */
325326
if (*start) start[1] = 0; /* Cut length of argument */
326-
tty_password = 0;
327+
tty_password = false;
327328
} else
328-
tty_password = 1;
329+
tty_password = true;
329330
break;
330331
case 'r':
331332
what_to_do = DO_REPAIR;
332333
break;
333334
case 'g':
334335
what_to_do = DO_CHECK;
335-
opt_upgrade = 1;
336+
opt_upgrade = true;
336337
break;
337338
case 'W':
338339
#ifdef _WIN32
@@ -341,12 +342,12 @@ static bool get_one_option(int optid, const struct my_option *opt,
341342
break;
342343
case '#':
343344
DBUG_PUSH(argument ? argument : "d:t:o");
344-
debug_check_flag = 1;
345+
debug_check_flag = true;
345346
break;
346347
#include "sslopt-case.h"
347348

348349
case OPT_TABLES:
349-
opt_databases = 0;
350+
opt_databases = false;
350351
break;
351352
case 'v':
352353
verbose++;
@@ -367,9 +368,9 @@ static bool get_one_option(int optid, const struct my_option *opt,
367368
fprintf(stderr,
368369
"Error: %s doesn't support multiple contradicting commands.\n",
369370
my_progname);
370-
return 1;
371+
return true;
371372
}
372-
return 0;
373+
return false;
373374
}
374375
}
375376

@@ -487,7 +488,7 @@ static int dbConnect(char *host, char *user, char *passwd) {
487488
DBerror(&mysql_connection, "when trying to connect");
488489
return 1;
489490
}
490-
mysql_connection.reconnect = 1;
491+
mysql_connection.reconnect = true;
491492
return 0;
492493
} /* dbConnect */
493494

client/check/mysqlcheck_core.cc

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2001, 2017, Oracle and/or its affiliates. All rights reserved.
2+
Copyright (c) 2001, 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,
@@ -44,12 +44,13 @@ using std::vector;
4444
#define KEY_PARTITIONING_CHANGED_STR "KEY () partitioning changed"
4545

4646
static MYSQL *sock = 0;
47-
static bool opt_alldbs = 0, opt_check_only_changed = 0, opt_extended = 0,
48-
opt_databases = 0, opt_fast = 0, opt_medium_check = 0,
49-
opt_quick = 0, opt_all_in_1 = 0, opt_silent = 0,
50-
opt_auto_repair = 0, ignore_errors = 0, opt_frm = 0,
51-
opt_fix_table_names = 0, opt_fix_db_names = 0, opt_upgrade = 0,
52-
opt_write_binlog = 1;
47+
static bool opt_alldbs = false, opt_check_only_changed = false,
48+
opt_extended = false, opt_databases = false, opt_fast = false,
49+
opt_medium_check = false, opt_quick = false, opt_all_in_1 = false,
50+
opt_silent = false, opt_auto_repair = false, ignore_errors = false,
51+
opt_frm = false, opt_fix_table_names = false,
52+
opt_fix_db_names = false, opt_upgrade = false,
53+
opt_write_binlog = true;
5354
static uint verbose = 0;
5455
static string opt_skip_database;
5556
int what_to_do = 0;
@@ -271,7 +272,7 @@ static void print_result() {
271272
char prev_alter[MAX_ALTER_STR_SIZE];
272273
uint i;
273274
size_t dot_pos;
274-
bool found_error = 0, table_rebuild = 0;
275+
bool found_error = false, table_rebuild = false;
275276

276277
res = mysql_use_result(sock);
277278
dot_pos = strlen(sock->db) + 1;
@@ -300,8 +301,8 @@ static void print_result() {
300301
tables4repair.push_back(escape_db_table_name(prev, dot_pos));
301302
}
302303
}
303-
found_error = 0;
304-
table_rebuild = 0;
304+
found_error = false;
305+
table_rebuild = false;
305306
prev_alter[0] = 0;
306307
if (opt_silent) continue;
307308
}
@@ -316,9 +317,9 @@ static void print_result() {
316317
}
317318
if (opt_auto_repair && strcmp(row[2], "note")) {
318319
const char *alter_txt = strstr(row[3], "ALTER TABLE");
319-
found_error = 1;
320+
found_error = true;
320321
if (alter_txt) {
321-
table_rebuild = 1;
322+
table_rebuild = true;
322323
if (!strncmp(row[3], KEY_PARTITIONING_CHANGED_STR,
323324
strlen(KEY_PARTITIONING_CHANGED_STR)) &&
324325
strstr(alter_txt, "PARTITION BY")) {
@@ -327,7 +328,7 @@ static void print_result() {
327328
"Error: Alter command too long (>= %d),"
328329
" please do \"%s\" or dump/reload to fix it!\n",
329330
MAX_ALTER_STR_SIZE, alter_txt);
330-
table_rebuild = 0;
331+
table_rebuild = false;
331332
prev_alter[0] = 0;
332333
} else {
333334
strncpy(prev_alter, alter_txt, MAX_ALTER_STR_SIZE - 1);

client/dump/mysql_object_reader.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
2+
Copyright (c) 2015, 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,
@@ -79,7 +79,7 @@ bool Mysql_object_reader::Rows_fetching_context::is_all_rows_processed() {
7979
void Mysql_object_reader::read_table_rows_task(
8080
Table_rows_dump_task *table_rows_dump_task,
8181
Item_processing_data *item_to_process) {
82-
bool has_generated_columns = 0;
82+
bool has_generated_columns = false;
8383
Mysql::Tools::Base::Mysql_query_runner *runner = this->get_runner();
8484

8585
if (!runner) return;
@@ -105,7 +105,7 @@ void Mysql_object_reader::read_table_rows_task(
105105
const Mysql::Tools::Base::Mysql_query_runner::Row &column_data = **it;
106106
if (column_data[1] == "STORED GENERATED" ||
107107
column_data[1] == "VIRTUAL GENERATED")
108-
has_generated_columns = 1;
108+
has_generated_columns = true;
109109
else
110110
column_names += this->quote_name(column_data[0]) + ",";
111111
}

0 commit comments

Comments
 (0)