Skip to content

Commit f1f743f

Browse files
committed
Bug#37471922: Auto-fix clang-tidy warnings [33/n] [noclose]
Generate fixes for a number of warnings that clang-tidy can fix automatically. This commit fixes the warning 'readability-else-after-return'. Change example: if (enable_async_client) return async_mysql_store_result_wrapper(mysql); - else - return mysql_store_result(mysql); + return mysql_store_result(mysql); Change-Id: I2dd490cc438f521c85a03d8ccffc3bce99cc6ddc
1 parent 86f5b52 commit f1f743f

File tree

195 files changed

+2622
-2966
lines changed

Some content is hidden

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

195 files changed

+2622
-2966
lines changed

client/completion_hash.cc

+2-3
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,9 @@ Bucket *find_all_matches(HashTable *ht, const char *str, uint length,
156156
if (!b) {
157157
*res_length = 0;
158158
return (Bucket *)nullptr;
159-
} else {
160-
*res_length = length;
161-
return b;
162159
}
160+
*res_length = length;
161+
return b;
163162
}
164163

165164
Bucket *find_longest_match(HashTable *ht, char *str, uint length,

client/mysql_config_editor.cc

+3-4
Original file line numberDiff line numberDiff line change
@@ -895,10 +895,9 @@ static void remove_option(DYNAMIC_STRING *file_buf, const char *path_name,
895895
}
896896
option_found = true;
897897
break;
898-
} else {
899-
/* Move to next line. */
900-
while ((--search_len > 1) && (*(++start) != '\n')) {
901-
}
898+
}
899+
/* Move to next line. */
900+
while ((--search_len > 1) && (*(++start) != '\n')) {
902901
}
903902
}
904903

client/mysql_secure_installation.cc

+3-3
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ static void execute_query_with_message(const char *query,
262262
static bool execute_query(const char **query, size_t length) {
263263
if (!mysql_real_query(&mysql_handle, (const char *)*query, (ulong)length))
264264
return false;
265-
else if (mysql_errno(&mysql_handle) == CR_SERVER_GONE_ERROR) {
265+
if (mysql_errno(&mysql_handle) == CR_SERVER_GONE_ERROR) {
266266
fprintf(stdout, " ... Failed! Error: %s\n", mysql_error(&mysql_handle));
267267
free_resources();
268268
exit(1);
@@ -537,8 +537,8 @@ static void set_opt_user_password(int component_set) {
537537
if (!execute_query(&query_const, (unsigned int)(end - query))) {
538538
my_free(query);
539539
break;
540-
} else
541-
fprintf(stdout, " ... Failed! Error: %s\n", mysql_error(&mysql_handle));
540+
}
541+
fprintf(stdout, " ... Failed! Error: %s\n", mysql_error(&mysql_handle));
542542
}
543543
}
544544
}

client/mysqladmin.cc

+2-1
Original file line numberDiff line numberDiff line change
@@ -1001,7 +1001,8 @@ static int execute_commands(MYSQL *mysql, int argc, char **argv) {
10011001
my_printf_error(0, "Too few arguments to change password",
10021002
error_flags);
10031003
return 1;
1004-
} else if (argc == 1) {
1004+
}
1005+
if (argc == 1) {
10051006
/* prompt for password */
10061007
typed_password = get_tty_password("New password: ");
10071008
verified = get_tty_password("Confirm new password: ");

client/mysqldump.cc

+23-23
Original file line numberDiff line numberDiff line change
@@ -3178,8 +3178,8 @@ static uint get_table_structure(const char *table, char *db, char *table_type,
31783178
my_free(scv_buff);
31793179

31803180
return 0;
3181-
} else
3182-
my_free(scv_buff);
3181+
}
3182+
my_free(scv_buff);
31833183

31843184
n_cols = mysql_num_rows(result);
31853185
if (0 != n_cols) {
@@ -5414,29 +5414,29 @@ static int do_show_binary_log_status(MYSQL *mysql_con) {
54145414
mysql_con, &source,
54155415
get_compatible_rpl_source_query("SHOW BINARY LOG STATUS").c_str())) {
54165416
return 1;
5417-
} else {
5418-
row = mysql_fetch_row(source);
5419-
if (row && row[0] && row[1]) {
5420-
/* SHOW BINARY LOG STATUS reports file and position */
5421-
print_comment(md_result_file, false,
5422-
"\n--\n-- Position to start replication or point-in-time "
5423-
"recovery from\n--\n\n");
5424-
fprintf(
5425-
md_result_file, "%s%s %s='%s', %s=%s;\n", comment_prefix,
5426-
get_compatible_rpl_replica_command("CHANGE REPLICATION SOURCE TO")
5427-
.c_str(),
5428-
get_compatible_rpl_replica_command("SOURCE_LOG_FILE").c_str(), row[0],
5429-
get_compatible_rpl_replica_command("SOURCE_LOG_POS").c_str(), row[1]);
5430-
check_io(md_result_file);
5431-
} else if (!opt_force) {
5432-
/* SHOW BINARY LOG STATUS reports nothing and --force is not enabled */
5433-
my_printf_error(0, "Error: Binlogging on server not active", MYF(0));
5434-
mysql_free_result(source);
5435-
maybe_exit(EX_MYSQLERR);
5436-
return 1;
5437-
}
5417+
}
5418+
row = mysql_fetch_row(source);
5419+
if (row && row[0] && row[1]) {
5420+
/* SHOW BINARY LOG STATUS reports file and position */
5421+
print_comment(md_result_file, false,
5422+
"\n--\n-- Position to start replication or point-in-time "
5423+
"recovery from\n--\n\n");
5424+
fprintf(
5425+
md_result_file, "%s%s %s='%s', %s=%s;\n", comment_prefix,
5426+
get_compatible_rpl_replica_command("CHANGE REPLICATION SOURCE TO")
5427+
.c_str(),
5428+
get_compatible_rpl_replica_command("SOURCE_LOG_FILE").c_str(), row[0],
5429+
get_compatible_rpl_replica_command("SOURCE_LOG_POS").c_str(), row[1]);
5430+
check_io(md_result_file);
5431+
} else if (!opt_force) {
5432+
/* SHOW BINARY LOG STATUS reports nothing and --force is not enabled */
5433+
my_printf_error(0, "Error: Binlogging on server not active", MYF(0));
54385434
mysql_free_result(source);
5435+
maybe_exit(EX_MYSQLERR);
5436+
return 1;
54395437
}
5438+
mysql_free_result(source);
5439+
54405440
return 0;
54415441
}
54425442

client/mysqlshow.cc

+2-4
Original file line numberDiff line numberDiff line change
@@ -426,10 +426,8 @@ static int list_dbs(MYSQL *mysql, const char *wild) {
426426
row = mysql_fetch_row(result);
427427
if (!my_strcasecmp(&my_charset_latin1, row[0], wild)) {
428428
mysql_free_result(result);
429-
if (opt_status)
430-
return list_table_status(mysql, wild, nullptr);
431-
else
432-
return list_tables(mysql, wild, nullptr);
429+
if (opt_status) return list_table_status(mysql, wild, nullptr);
430+
return list_tables(mysql, wild, nullptr);
433431
}
434432
}
435433

client/mysqltest.cc

+44-79
Original file line numberDiff line numberDiff line change
@@ -370,10 +370,8 @@ const char *get_filename_from_path(const char *path) {
370370
fname = strrchr(path, '\\');
371371
else
372372
fname = strrchr(path, '/');
373-
if (fname == nullptr)
374-
return path;
375-
else
376-
return ++fname;
373+
if (fname == nullptr) return path;
374+
return ++fname;
377375
}
378376

379377
static uint opt_protocol = 0;
@@ -828,12 +826,9 @@ static int async_mysql_next_result_wrapper(MYSQL *mysql) {
828826
const int result = socket_event_listen(mysql_get_socket_descriptor(mysql));
829827
if (result == -1) return 1;
830828
}
831-
if (status == NET_ASYNC_ERROR)
832-
return 1;
833-
else if (status == NET_ASYNC_COMPLETE_NO_MORE_RESULTS)
834-
return -1;
835-
else
836-
return 0;
829+
if (status == NET_ASYNC_ERROR) return 1;
830+
if (status == NET_ASYNC_COMPLETE_NO_MORE_RESULTS) return -1;
831+
return 0;
837832
}
838833

839834
static MYSQL *async_mysql_real_connect_wrapper(
@@ -847,10 +842,8 @@ static MYSQL *async_mysql_real_connect_wrapper(
847842
NET_ASYNC_NOT_READY) {
848843
t.check();
849844
}
850-
if (status == NET_ASYNC_ERROR)
851-
return nullptr;
852-
else
853-
return mysql;
845+
if (status == NET_ASYNC_ERROR) return nullptr;
846+
return mysql;
854847
}
855848

856849
static int async_mysql_query_wrapper(MYSQL *mysql, const char *query) {
@@ -885,17 +878,13 @@ static void async_mysql_free_result_wrapper(MYSQL_RES *result) {
885878
--async-client option is set or not.
886879
*/
887880
static MYSQL_ROW mysql_fetch_row_wrapper(MYSQL_RES *res) {
888-
if (enable_async_client)
889-
return async_mysql_fetch_row_wrapper(res);
890-
else
891-
return mysql_fetch_row(res);
881+
if (enable_async_client) return async_mysql_fetch_row_wrapper(res);
882+
return mysql_fetch_row(res);
892883
}
893884

894885
static MYSQL_RES *mysql_store_result_wrapper(MYSQL *mysql) {
895-
if (enable_async_client)
896-
return async_mysql_store_result_wrapper(mysql);
897-
else
898-
return mysql_store_result(mysql);
886+
if (enable_async_client) return async_mysql_store_result_wrapper(mysql);
887+
return mysql_store_result(mysql);
899888
}
900889

901890
static int mysql_real_query_wrapper(MYSQL *mysql, const char *query,
@@ -905,8 +894,7 @@ static int mysql_real_query_wrapper(MYSQL *mysql, const char *query,
905894

906895
if (enable_async_client)
907896
return async_mysql_real_query_wrapper(mysql, query, length);
908-
else
909-
return mysql_real_query(mysql, query, length);
897+
return mysql_real_query(mysql, query, length);
910898
}
911899

912900
static int mysql_send_query_wrapper(MYSQL *mysql, const char *query,
@@ -916,8 +904,7 @@ static int mysql_send_query_wrapper(MYSQL *mysql, const char *query,
916904

917905
if (enable_async_client)
918906
return async_mysql_send_query_wrapper(mysql, query, length);
919-
else
920-
return mysql_send_query(mysql, query, length);
907+
return mysql_send_query(mysql, query, length);
921908
}
922909

923910
static bool mysql_read_query_result_wrapper(MYSQL *mysql) {
@@ -933,17 +920,13 @@ static int mysql_query_wrapper(MYSQL *mysql, const char *query) {
933920
int rc;
934921
if (0 != (rc = global_attrs->set_params(mysql))) return rc;
935922

936-
if (enable_async_client)
937-
return async_mysql_query_wrapper(mysql, query);
938-
else
939-
return mysql_query(mysql, query);
923+
if (enable_async_client) return async_mysql_query_wrapper(mysql, query);
924+
return mysql_query(mysql, query);
940925
}
941926

942927
static int mysql_next_result_wrapper(MYSQL *mysql) {
943-
if (enable_async_client)
944-
return async_mysql_next_result_wrapper(mysql);
945-
else
946-
return mysql_next_result(mysql);
928+
if (enable_async_client) return async_mysql_next_result_wrapper(mysql);
929+
return mysql_next_result(mysql);
947930
}
948931

949932
static MYSQL *mysql_real_connect_wrapper(MYSQL *mysql, const char *host,
@@ -954,16 +937,13 @@ static MYSQL *mysql_real_connect_wrapper(MYSQL *mysql, const char *host,
954937
if (enable_async_client)
955938
return async_mysql_real_connect_wrapper(mysql, host, user, passwd, db, port,
956939
unix_socket, client_flag);
957-
else
958-
return mysql_real_connect(mysql, host, user, passwd, db, port, unix_socket,
959-
client_flag);
940+
return mysql_real_connect(mysql, host, user, passwd, db, port, unix_socket,
941+
client_flag);
960942
}
961943

962944
static void mysql_free_result_wrapper(MYSQL_RES *result) {
963-
if (enable_async_client)
964-
return async_mysql_free_result_wrapper(result);
965-
else
966-
return mysql_free_result(result);
945+
if (enable_async_client) return async_mysql_free_result_wrapper(result);
946+
return mysql_free_result(result);
967947
}
968948

969949
/* async client test code (end) */
@@ -5294,30 +5274,18 @@ static void check_variable_name(const char *var_name, const char *var_name_end,
52945274
op - character pointer to mathematical expression
52955275
*/
52965276
static bool is_operator(const char *op) {
5297-
if (*op == '+')
5298-
return true;
5299-
else if (*op == '-')
5300-
return true;
5301-
else if (*op == '*')
5302-
return true;
5303-
else if (*op == '/')
5304-
return true;
5305-
else if (*op == '%')
5306-
return true;
5307-
else if (*op == '&' && *(op + 1) == '&')
5308-
return true;
5309-
else if (*op == '|' && *(op + 1) == '|')
5310-
return true;
5311-
else if (*op == '&')
5312-
return true;
5313-
else if (*op == '|')
5314-
return true;
5315-
else if (*op == '^')
5316-
return true;
5317-
else if (*op == '>' && *(op + 1) == '>')
5318-
return true;
5319-
else if (*op == '<' && *(op + 1) == '<')
5320-
return true;
5277+
if (*op == '+') return true;
5278+
if (*op == '-') return true;
5279+
if (*op == '*') return true;
5280+
if (*op == '/') return true;
5281+
if (*op == '%') return true;
5282+
if (*op == '&' && *(op + 1) == '&') return true;
5283+
if (*op == '|' && *(op + 1) == '|') return true;
5284+
if (*op == '&') return true;
5285+
if (*op == '|') return true;
5286+
if (*op == '^') return true;
5287+
if (*op == '>' && *(op + 1) == '>') return true;
5288+
if (*op == '<' && *(op + 1) == '<') return true;
53215289

53225290
return false;
53235291
}
@@ -6141,18 +6109,17 @@ static void do_disable_warnings(struct st_command *command) {
61416109
// Set 'disable_warnings' property value to 1
61426110
set_property(command, P_WARN, true);
61436111
return;
6144-
} else {
6145-
// Parse the warning list argument specified with disable_warnings
6146-
// command.
6147-
parse_warning_list_argument(command);
6112+
}
6113+
// Parse the warning list argument specified with disable_warnings
6114+
// command.
6115+
parse_warning_list_argument(command);
61486116

6149-
// Update the environment variables containing the list of disabled
6150-
// and enabled warnings.
6151-
update_disabled_enabled_warnings_list_var();
6117+
// Update the environment variables containing the list of disabled
6118+
// and enabled warnings.
6119+
update_disabled_enabled_warnings_list_var();
61526120

6153-
// Set 'disable_warnings' property value to 1
6154-
set_property(command, P_WARN, true);
6155-
}
6121+
// Set 'disable_warnings' property value to 1
6122+
set_property(command, P_WARN, true);
61566123

61576124
command->last_argument = command->end;
61586125
}
@@ -10920,10 +10887,8 @@ static struct st_replace_regex *init_replace_regex(const char *expr) {
1092010887
}
1092110888

1092210889
if (p == expr_end || ++p == expr_end) {
10923-
if (!res->regex_arr.empty())
10924-
break;
10925-
else
10926-
goto err;
10890+
if (!res->regex_arr.empty()) break;
10891+
goto err;
1092710892
}
1092810893
/* we found the start */
1092910894
reg.pattern = buf_p;

client/mysqltest/regular_expressions.cc

+1-2
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,6 @@ int search_protocol_re(std::regex *re, const char *str) {
258258

259259
// Match found
260260
return 1;
261-
} else {
262-
return 0;
263261
}
262+
return 0;
264263
}

client/path.cc

+6-7
Original file line numberDiff line numberDiff line change
@@ -145,14 +145,13 @@ bool Path::exists() {
145145
if (dir == nullptr) return false;
146146
my_dirend(dir);
147147
return true;
148-
} else {
149-
MY_STAT s;
150-
std::string qpath(m_path);
151-
qpath.append(FN_DIRSEP).append(m_filename);
152-
if (my_stat(qpath.c_str(), &s, MYF(0)) == nullptr) return false;
153-
if (!MY_S_ISREG(s.st_mode)) return false;
154-
return true;
155148
}
149+
MY_STAT s;
150+
std::string qpath(m_path);
151+
qpath.append(FN_DIRSEP).append(m_filename);
152+
if (my_stat(qpath.c_str(), &s, MYF(0)) == nullptr) return false;
153+
if (!MY_S_ISREG(s.st_mode)) return false;
154+
return true;
156155
}
157156

158157
std::string Path::to_str() {

components/example/test_string_service_long.cc

+4-4
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,11 @@ mysql_service_status_t test_string_service_init() {
7070
if (!(test_text = (char *)malloc(MAX_BUFFER_LENGTH + 1))) {
7171
WRITE_LOG("%s\n", "Allcoate buffer failed. Stopped test execution.");
7272
return (true);
73-
} else {
74-
for (int i = 0; i < MAX_BUFFER_LENGTH / TEST_TEXT_LIT_LENGTH; i++) {
75-
strcpy(&test_text[i * TEST_TEXT_LIT_LENGTH], test_text_lit);
76-
}
7773
}
74+
for (int i = 0; i < MAX_BUFFER_LENGTH / TEST_TEXT_LIT_LENGTH; i++) {
75+
strcpy(&test_text[i * TEST_TEXT_LIT_LENGTH], test_text_lit);
76+
}
77+
7878
WRITE_LOG("%s\n", test_text);
7979

8080
if (mysql_service_mysql_string_factory->create(&out_string)) {

0 commit comments

Comments
 (0)