Skip to content

Commit 40032fe

Browse files
committed
Bug#37471922: Auto-fix clang-tidy warnings [17/n] [noclose]
Generate fixes for a number of warnings that clang-tidy can fix automatically. This commit fixes the warning 'readability-simplify-boolean-expr'. Change example: - if (check_length(size) == true) { + if (check_length(size)) { Change-Id: If3c334e3b040a69ddb756113eda17f261ed8c8f3
1 parent 4edcd72 commit 40032fe

File tree

138 files changed

+412
-623
lines changed

Some content is hidden

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

138 files changed

+412
-623
lines changed

client/mysql_config_editor.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,7 @@ static int remove_command(void) {
592592

593593
/* Warn if no login path is specified. */
594594
if (opt_warn && ((locate_login_path(&file_buf, opt_login_path)) != nullptr) &&
595-
(login_path_specified == false)) {
595+
(!login_path_specified)) {
596596
int choice;
597597
printf(
598598
"WARNING : No login path specified, so options from the default "

client/mysql_secure_installation.cc

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ static int get_response(const char *opt_message, int default_answer = -1) {
202202
int i = 0;
203203
if (opt_message) {
204204
fprintf(stdout, "%s", opt_message);
205-
if (opt_use_default == true && default_answer != -1) {
205+
if (opt_use_default && default_answer != -1) {
206206
fprintf(stdout, " %c \n", (char)default_answer);
207207
return default_answer;
208208
}
@@ -462,9 +462,7 @@ static bool mysql_set_password(MYSQL *mysql, char *password) {
462462
static bool mysql_expire_password(MYSQL *mysql) {
463463
char sql[] = "UPDATE mysql.user SET password_expired= 'Y'";
464464
const size_t sql_len = strlen(sql);
465-
if (mysql_real_query(mysql, sql, (ulong)sql_len)) return false;
466-
467-
return true;
465+
return mysql_real_query(mysql, sql, (ulong)sql_len) == 0;
468466
}
469467

470468
/**
@@ -818,7 +816,7 @@ int main(int argc, char *argv[]) {
818816
if (!hadpass) {
819817
fprintf(stdout, "Please set the password for %s here.\n", opt_user);
820818
set_opt_user_password(component_set);
821-
} else if (opt_use_default == false) {
819+
} else if (!opt_use_default) {
822820
char prompt[256];
823821
fprintf(stdout, "Using existing password for %s.\n", opt_user);
824822

@@ -852,8 +850,8 @@ int main(int argc, char *argv[]) {
852850
to be marked for expiration upon exit so the DBA will remember to set a new
853851
one.
854852
*/
855-
if (g_expire_password_on_exit == true) {
856-
if (mysql_expire_password(&mysql_handle) == false) {
853+
if (g_expire_password_on_exit) {
854+
if (!mysql_expire_password(&mysql_handle)) {
857855
fprintf(stdout,
858856
"... Failed to expire password!\n"
859857
"** Please consult the MySQL server documentation. **\n"

client/mysqladmin.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ int main(int argc, char *argv[]) {
468468
(char *)&opt_enable_cleartext_plugin);
469469

470470
first_command = find_type(argv[0], &command_typelib, FIND_TYPE_BASIC);
471-
can_handle_passwords = first_command == ADMIN_PASSWORD ? true : false;
471+
can_handle_passwords = first_command == ADMIN_PASSWORD;
472472
mysql_options(&mysql, MYSQL_OPT_CAN_HANDLE_EXPIRED_PASSWORDS,
473473
&can_handle_passwords);
474474

client/mysqldump.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5308,10 +5308,10 @@ static int dump_selected_tables(char *db, char **table_names, int tables) {
53085308

53095309
/* Can't LOCK TABLES in I_S / P_S, so don't try. */
53105310
if (lock_tables &&
5311-
!(mysql_get_server_version(mysql) >= FIRST_INFORMATION_SCHEMA_VERSION &&
5312-
!my_strcasecmp(&my_charset_latin1, db, INFORMATION_SCHEMA_DB_NAME)) &&
5313-
!(mysql_get_server_version(mysql) >= FIRST_PERFORMANCE_SCHEMA_VERSION &&
5314-
!my_strcasecmp(&my_charset_latin1, db, PERFORMANCE_SCHEMA_DB_NAME))) {
5311+
(mysql_get_server_version(mysql) < FIRST_INFORMATION_SCHEMA_VERSION ||
5312+
my_strcasecmp(&my_charset_latin1, db, INFORMATION_SCHEMA_DB_NAME)) &&
5313+
(mysql_get_server_version(mysql) < FIRST_PERFORMANCE_SCHEMA_VERSION ||
5314+
my_strcasecmp(&my_charset_latin1, db, PERFORMANCE_SCHEMA_DB_NAME))) {
53155315
if (mysql_real_query(mysql, lock_tables_query.str,
53165316
(ulong)(lock_tables_query.length - 1))) {
53175317
if (!opt_force) {
@@ -5962,7 +5962,7 @@ static bool get_gtid_mode(MYSQL *mysql_con) {
59625962
get the gtid_mode value from the second column.
59635963
*/
59645964
gtid_mode_val = gtid_mode_row ? (char *)gtid_mode_row[1] : nullptr;
5965-
gtid_mode = (gtid_mode_val && strcmp(gtid_mode_val, "OFF")) ? true : false;
5965+
gtid_mode = gtid_mode_val && strcmp(gtid_mode_val, "OFF");
59665966
mysql_free_result(gtid_mode_res);
59675967

59685968
return gtid_mode;

client/mysqlslap.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1164,8 +1164,7 @@ static int get_options(int *argc, char ***argv) {
11641164
that we actually added a key!
11651165
*/
11661166
if (auto_generate_sql && auto_generate_sql_type[0] == 'k')
1167-
if (auto_generate_sql_autoincrement == false &&
1168-
auto_generate_sql_guid_primary == false) {
1167+
if (!auto_generate_sql_autoincrement && !auto_generate_sql_guid_primary) {
11691168
fprintf(stderr, "%s: Can't perform key test without a primary key!\n",
11701169
my_progname);
11711170
exit(1);

client/mysqltest.cc

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -816,10 +816,7 @@ static bool async_mysql_read_query_result_wrapper(MYSQL *mysql) {
816816
const int result = socket_event_listen(mysql_get_socket_descriptor(mysql));
817817
if (result == -1) return true;
818818
}
819-
if (status == NET_ASYNC_ERROR) {
820-
return true;
821-
}
822-
return false;
819+
return status == NET_ASYNC_ERROR;
823820
}
824821

825822
static int async_mysql_next_result_wrapper(MYSQL *mysql) {
@@ -2478,7 +2475,7 @@ void var_set(const char *var_name, const char *var_name_end,
24782475
var_name++;
24792476

24802477
digit = *var_name - '0';
2481-
if (!(digit < 10 && digit >= 0)) {
2478+
if (digit >= 10 || digit < 0) {
24822479
v = var_obtain(var_name, (uint)(var_name_end - var_name));
24832480
} else
24842481
v = var_reg + digit;
@@ -7188,7 +7185,7 @@ static void do_block(enum block_cmd cmd, struct st_command *command) {
71887185

71897186
case NE_OP:
71907187
if (v.is_int)
7191-
v.int_val = !(v2.is_int && v2.int_val == v.int_val);
7188+
v.int_val = !v2.is_int || v2.int_val != v.int_val;
71927189
else
71937190
v.int_val = (std::strcmp(v.str_val, v2.str_val) != 0);
71947191
break;

client/path.cc

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,7 @@ bool Path::qpath(const std::string &qp) {
116116
filename(qp.substr(idx + 1, qp.size() - idx));
117117
path(qp.substr(0, idx));
118118
}
119-
if (is_qualified_path())
120-
return true;
121-
else
122-
return false;
119+
return is_qualified_path();
123120
}
124121

125122
bool Path::normalize_path() {

components/audit_api_message_emit/audit_api_message_emit.cc

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ static int arg_check(IError_handler &handler, unsigned int arg_count,
265265
/*
266266
At least one argument count was matched against definition.
267267
*/
268-
if (result == false) {
268+
if (!result) {
269269
handler.error("Invalid argument count.");
270270
return -1;
271271
}
@@ -287,7 +287,7 @@ static int arg_check(IError_handler &handler, unsigned int arg_count,
287287
result = true;
288288
}
289289

290-
if (result == false) {
290+
if (!result) {
291291
handler.error("Invalid argument type [%d].", i);
292292
return -1;
293293
}
@@ -301,7 +301,7 @@ static int arg_check(IError_handler &handler, unsigned int arg_count,
301301
handler, args[i], arg_lengths[i], i))))
302302
result = true;
303303

304-
if (result == false) {
304+
if (!result) {
305305
/*
306306
Error has been already set by the validator.
307307
*/
@@ -369,9 +369,7 @@ static bool arg_check(IError_handler &handler, UDF_ARGS *args) {
369369
arg_lengths += audit_log_extra_args_def[arg_res].count;
370370
};
371371

372-
if (set_args_charset_info(args, handler)) return true;
373-
374-
return false;
372+
return set_args_charset_info(args, handler);
375373
}
376374

377375
/**

components/libminchassis/dynamic_loader_scheme_file.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ DEFINE_BOOL_METHOD(mysql_dynamic_loader_scheme_file_imp::load,
158158

159159
/* Check if library is not already loaded, by comparing "list_components"
160160
function address. */
161-
if (library_entry_set.insert(list_func).second == false) {
161+
if (!library_entry_set.insert(list_func).second) {
162162
return true;
163163
}
164164

@@ -175,7 +175,7 @@ DEFINE_BOOL_METHOD(mysql_dynamic_loader_scheme_file_imp::load,
175175

176176
/* Add library and it's handle to list of loaded libraries. */
177177

178-
if (object_files_list.emplace(urn_string, handle).second == false) {
178+
if (!object_files_list.emplace(urn_string, handle).second) {
179179
return true;
180180
}
181181

components/pfs_component/pfs_example_continent.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ int write_rows_from_component(Continent_Table_Handle *handle) {
232232
int i = (continent_next_available_index + 1) % CONTINENT_MAX_ROWS;
233233
int itr_count = 0;
234234
while (itr_count < CONTINENT_MAX_ROWS) {
235-
if (continent_records_array[i].m_exist == false) {
235+
if (!continent_records_array[i].m_exist) {
236236
continent_next_available_index = i;
237237
break;
238238
}

components/pfs_component/pfs_example_country.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ int country_write_row_values(PSI_table_handle *handle) {
292292
int i = (country_next_available_index + 1) % COUNTRY_MAX_ROWS;
293293
int itr_count = 0;
294294
while (itr_count < COUNTRY_MAX_ROWS) {
295-
if (country_records_array[i].m_exist == false) {
295+
if (!country_records_array[i].m_exist) {
296296
country_next_available_index = i;
297297
break;
298298
}

components/reference_cache/cache.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ bool cache_imp::get(unsigned service_name_index, const my_h_service **out_ref) {
5858
// cache hit
5959
*out_ref = m_cache[service_name_index];
6060
}
61-
return *out_ref ? false : true;
61+
return *out_ref == nullptr;
6262
}
6363

6464
// cache miss
@@ -155,7 +155,7 @@ bool cache_imp::get(unsigned service_name_index, const my_h_service **out_ref) {
155155
}
156156
}
157157
m_populated = true;
158-
return *out_ref ? false : true;
158+
return *out_ref == nullptr;
159159
}
160160

161161
bool cache_imp::flush() {

components/reference_cache/component.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ static DEFINE_BOOL_METHOD(create, (const char *service_names[],
5252

5353
*out_channel =
5454
reinterpret_cast<reference_caching_channel>(channel_imp::create(refs));
55-
return *out_channel ? false : true;
55+
return *out_channel == nullptr;
5656
} catch (...) {
5757
return true;
5858
}

components/test/event_tracking_test/event_tracking_producer_a.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -430,8 +430,7 @@ bool Event_producer::generate_events() {
430430

431431
static mysql_service_status_t init() {
432432
g_event_producer = new (std::nothrow) Event_producer();
433-
if (!g_event_producer || g_event_producer->generate_events()) return true;
434-
return false;
433+
return !g_event_producer || g_event_producer->generate_events();
435434
}
436435

437436
static mysql_service_status_t deinit() {

components/test/event_tracking_test/event_tracking_producer_b.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,7 @@ bool Event_producer::generate_events() {
143143

144144
static mysql_service_status_t init() {
145145
g_event_producer = new (std::nothrow) Event_producer();
146-
if (!g_event_producer || g_event_producer->generate_events()) return true;
147-
return false;
146+
return !g_event_producer || g_event_producer->generate_events();
148147
}
149148

150149
static mysql_service_status_t deinit() {

components/test/event_tracking_test/event_tracking_test.cc

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,7 @@ static bool get_one_option(int optid, const struct my_option *, char *) {
9595
}
9696

9797
static bool check_options_for_sanity() {
98-
if (g_component_dir == nullptr || !*g_component_dir) {
99-
return true;
100-
}
101-
return false;
98+
return g_component_dir == nullptr || !*g_component_dir;
10299
}
103100

104101
static bool get_options(int argc, char **argv, int &exit_code) {
@@ -173,7 +170,7 @@ int main(int argc, char **argv) {
173170
full_path.append("/");
174171
full_path.append(component);
175172
const char *urn[] = {full_path.c_str()};
176-
return dynamic_loader->load(urn, 1) ? true : false;
173+
return dynamic_loader->load(urn, 1) != 0;
177174
};
178175

179176
auto unload_component = [&dynamic_loader](const char *component_dir,

components/test/keyring_encryption_test/components.cc

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -164,18 +164,19 @@ bool Keyring_encryption_test::test_aes() {
164164
}
165165
const std::string iv1("abcdefgh12345678");
166166

167-
if (aes->encrypt("aes_key_invalid", "keyring_aes_test", mode.c_str(),
168-
block_size,
169-
reinterpret_cast<const unsigned char *>(iv1.c_str()),
170-
padding, plaintext, plaintext_length, output_1.get(),
171-
ciphertext_length, &ciphertext_length) == false) {
167+
if (!static_cast<bool>(aes->encrypt(
168+
"aes_key_invalid", "keyring_aes_test", mode.c_str(), block_size,
169+
reinterpret_cast<const unsigned char *>(iv1.c_str()), padding,
170+
plaintext, plaintext_length, output_1.get(), ciphertext_length,
171+
&ciphertext_length))) {
172172
std::cerr << "Failed negative test for AES-CBC-256" << std::endl;
173173
return false;
174174
}
175-
if (aes->encrypt("secret_key_1", "keyring_aes_test", mode.c_str(), block_size,
176-
reinterpret_cast<const unsigned char *>(iv1.c_str()),
177-
padding, plaintext, plaintext_length, output_1.get(),
178-
ciphertext_length, &ciphertext_length) == false) {
175+
if (!static_cast<bool>(aes->encrypt(
176+
"secret_key_1", "keyring_aes_test", mode.c_str(), block_size,
177+
reinterpret_cast<const unsigned char *>(iv1.c_str()), padding,
178+
plaintext, plaintext_length, output_1.get(), ciphertext_length,
179+
&ciphertext_length))) {
179180
std::cerr << "Failed negative test for AES-CBC-256" << std::endl;
180181
return false;
181182
}
@@ -206,19 +207,20 @@ bool Keyring_encryption_test::test_aes() {
206207
}
207208
memset(output_2.get(), 0, decrypted_length);
208209

209-
if (aes->decrypt("aes_key_invalid", "keyring_aes_test", mode.c_str(),
210-
block_size,
211-
reinterpret_cast<const unsigned char *>(iv1.c_str()),
212-
padding, output_1.get(), ciphertext_length, output_2.get(),
213-
decrypted_length, &decrypted_length) == false) {
210+
if (!static_cast<bool>(aes->decrypt(
211+
"aes_key_invalid", "keyring_aes_test", mode.c_str(), block_size,
212+
reinterpret_cast<const unsigned char *>(iv1.c_str()), padding,
213+
output_1.get(), ciphertext_length, output_2.get(), decrypted_length,
214+
&decrypted_length))) {
214215
std::cerr << "Failed negative test for AES-CBC-256" << std::endl;
215216
return false;
216217
}
217218

218-
if (aes->decrypt("secret_key_1", "keyring_aes_test", mode.c_str(), block_size,
219-
reinterpret_cast<const unsigned char *>(iv1.c_str()),
220-
padding, output_1.get(), ciphertext_length, output_2.get(),
221-
decrypted_length, &decrypted_length) == false) {
219+
if (!static_cast<bool>(aes->decrypt(
220+
"secret_key_1", "keyring_aes_test", mode.c_str(), block_size,
221+
reinterpret_cast<const unsigned char *>(iv1.c_str()), padding,
222+
output_1.get(), ciphertext_length, output_2.get(), decrypted_length,
223+
&decrypted_length))) {
222224
std::cerr << "Failed negative test for AES-CBC-256" << std::endl;
223225
return false;
224226
}

components/test/keyring_encryption_test/keyring_encryption.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ int main(int argc, char **argv) {
6767
constexpr int exit_status = EXIT_FAILURE;
6868

6969
int exit_code;
70-
if (process_options(&argc, &argv, exit_code) == false) {
70+
if (!process_options(&argc, &argv, exit_code)) {
7171
std::cerr << "Error processing options" << std::endl;
7272
return exit_status;
7373
}

components/test/keyring_encryption_test/options.cc

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,8 @@ bool get_one_option(int optid, const struct my_option *, char *) {
101101
}
102102

103103
static bool check_options_for_sanity() {
104-
if (Options::s_component_dir == nullptr || !*Options::s_component_dir ||
105-
Options::s_keyring == nullptr || !*Options::s_keyring) {
106-
return false;
107-
}
108-
return true;
104+
return !(Options::s_component_dir == nullptr || !*Options::s_component_dir ||
105+
Options::s_keyring == nullptr || !*Options::s_keyring);
109106
}
110107

111108
static bool get_options(int argc, char **argv, int &exit_code) {
@@ -114,7 +111,7 @@ static bool get_options(int argc, char **argv, int &exit_code) {
114111
return false;
115112
}
116113

117-
if (check_options_for_sanity() == false) return false;
114+
if (!check_options_for_sanity()) return false;
118115

119116
return true;
120117
}

components/test/table_access/test_table_access.cc

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -782,11 +782,7 @@ static bool udf_init(UDF_INIT *initid, UDF_ARGS *args, char *message) {
782782
const char *attr_name = "charset";
783783
const char *attr_value = "utf8mb4";
784784
char *attr_value_2 = const_cast<char *>(attr_value);
785-
if (udf_metadata_srv->result_set(initid, attr_name, attr_value_2)) {
786-
return true;
787-
}
788-
789-
return false;
785+
return udf_metadata_srv->result_set(initid, attr_name, attr_value_2) != 0;
790786
}
791787

792788
static void udf_deinit(UDF_INIT *) {}

0 commit comments

Comments
 (0)