Skip to content

Commit d238833

Browse files
committed
Bug#37471922: Auto-fix clang-tidy warnings [64/n] [noclose]
Generate fixes for a number of warnings that clang-tidy can fix automatically. This commit fixes the warning 'modernize-loop-convert'. Change example: - for (int i = 0; i < m_noOfSectionNames; i++) { - const char *s = m_sectionNames[i]; + for (auto s : m_sectionNames) { Change-Id: I6582ea5235080425d85b40dc50df82d52d8fcc1c
1 parent b08d494 commit d238833

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

+228
-318
lines changed

client/mysql_config_editor.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1244,9 +1244,9 @@ bool generate_login_key() {
12441244

12451245
verbose_msg("Generating a new key.\n");
12461246
/* Get a sequence of random non-printable ASCII */
1247-
for (uint i = 0; i < LOGIN_KEY_LEN; i++) {
1247+
for (char &i : my_key) {
12481248
bool failed;
1249-
my_key[i] = (char)((int)(my_rnd_ssl(&failed) * 100000) % 32);
1249+
i = (char)((int)(my_rnd_ssl(&failed) * 100000) % 32);
12501250
if (failed) return true;
12511251
}
12521252
return false;

client/mysqldump.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1774,8 +1774,8 @@ static bool do_ignore_error() {
17741774

17751775
if (last_errno == 0) goto done;
17761776

1777-
for (uint *it = ignore_error.begin(); it != ignore_error.end(); ++it) {
1778-
if (last_errno == *it) {
1777+
for (unsigned int &it : ignore_error) {
1778+
if (last_errno == it) {
17791779
found = true;
17801780
break;
17811781
}

client/mysqltest.cc

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1526,8 +1526,8 @@ static void free_used_memory() {
15261526
my_free((*q));
15271527
}
15281528

1529-
for (size_t i = 0; i < 10; i++) {
1530-
if (var_reg[i].alloced_len) my_free(var_reg[i].str_val);
1529+
for (auto &i : var_reg) {
1530+
if (i.alloced_len) my_free(i.str_val);
15311531
}
15321532

15331533
delete q_lines;
@@ -2569,8 +2569,7 @@ static void set_property(st_command *command, enum_prop property, bool value) {
25692569
void revert_properties() {
25702570
if (!once_property) return;
25712571

2572-
for (std::size_t i = 0; i < P_MAX; i++) {
2573-
Property &prop = prop_list[i];
2572+
for (auto &prop : prop_list) {
25742573
if (prop.set) {
25752574
*prop.var = prop.old;
25762575
prop.set = false;
@@ -6224,9 +6223,8 @@ static void do_error(struct st_command *command) {
62246223
die("The sqlstate must be exactly %d chars long.", SQLSTATE_LENGTH);
62256224

62266225
// Check the validity of an SQLSTATE string.
6227-
for (std::size_t i = 0; i < error.length(); i++) {
6228-
if (!my_isdigit(charset_info, error[i]) &&
6229-
!my_isupper(charset_info, error[i]))
6226+
for (char i : error) {
6227+
if (!my_isdigit(charset_info, i) && !my_isupper(charset_info, i))
62306228
die("The sqlstate may only consist of digits[0-9] and _uppercase_ "
62316229
"letters.");
62326230
}

client/mysqltest/expected_errors.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ std::string Expected_errors::error_list() {
3939

4040
std::vector<unsigned int> Expected_errors::errors() {
4141
std::vector<unsigned int> errors;
42-
for (std::size_t i = 0; i < m_errors.size(); i++) {
43-
errors.push_back(m_errors.at(i)->error_code());
42+
for (auto &m_error : m_errors) {
43+
errors.push_back(m_error->error_code());
4444
}
4545
return errors;
4646
}

client/mysqltest/expected_warnings.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@
2626
void Expected_warnings::add_warning(std::uint32_t warning_code,
2727
const char *warning_name,
2828
bool once_property) {
29-
for (std::size_t i = 0; i < m_warnings.size(); i++) {
29+
for (auto &m_warning : m_warnings) {
3030
// Warning already exist, don't add it.
31-
if (m_warnings.at(i)->warning_code() == warning_code) return;
31+
if (m_warning->warning_code() == warning_code) return;
3232
}
3333

3434
// Add a new warning to the existing list.

components/pfs_component/pfs_example_continent.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ Continent_record continent_records_array[CONTINENT_MAX_ROWS] = {{"", 0, false}};
4141

4242
int continent_delete_all_rows() {
4343
native_mutex_lock(&LOCK_continent_records_array);
44-
for (int i = 0; i < CONTINENT_MAX_ROWS; i++)
45-
continent_records_array[i].m_exist = false;
44+
for (auto &i : continent_records_array) i.m_exist = false;
4645
continent_rows_in_table = 0;
4746
continent_next_available_index = 0;
4847
native_mutex_unlock(&LOCK_continent_records_array);

components/pfs_component/pfs_example_country.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -421,8 +421,7 @@ int country_delete_row_values(PSI_table_handle *handle) {
421421

422422
int country_delete_all_rows() {
423423
native_mutex_lock(&LOCK_country_records_array);
424-
for (int i = 0; i < COUNTRY_MAX_ROWS; i++)
425-
country_records_array[i].m_exist = false;
424+
for (auto &i : country_records_array) i.m_exist = false;
426425
country_rows_in_table = 0;
427426
country_next_available_index = 0;
428427
native_mutex_unlock(&LOCK_country_records_array);

components/test/test_audit_api_message.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,8 @@ static mysql_service_status_t init() {
186186

187187
static mysql_service_status_t deinit() {
188188
int was_present = 0;
189-
for (size_t i = 0; i < no_udfs; ++i)
190-
mysql_service_udf_registration->udf_unregister(udf_names[i], &was_present);
189+
for (auto udf_name : udf_names)
190+
mysql_service_udf_registration->udf_unregister(udf_name, &was_present);
191191

192192
return false;
193193
}

components/test/test_event_tracking_consumer.cc

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -259,9 +259,7 @@ class Event_tracking_counters {
259259
public:
260260
/** Constructor */
261261
Event_tracking_counters() {
262-
for (unsigned int i = 0; i < static_cast<unsigned int>(Event_types::LAST);
263-
++i)
264-
event_counters_[i] = 0;
262+
for (auto &event_counter : event_counters_) event_counter = 0;
265263
}
266264

267265
/** Destructor */
@@ -311,9 +309,7 @@ class Event_tracking_counters {
311309
}
312310

313311
void reset_all() {
314-
for (unsigned int index = 0;
315-
index < static_cast<unsigned int>(Event_types::LAST); ++index)
316-
event_counters_[index] = 0;
312+
for (auto &event_counter : event_counters_) event_counter = 0;
317313
}
318314

319315
private:

libmysql/authentication_kerberos/gssapi_utility.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,13 @@ static void gssapi_errmsg(OM_uint32 major, OM_uint32 minor, char *buf,
3838
char *end = t_message + size - 1;
3939
int types[] = {GSS_C_GSS_CODE, GSS_C_MECH_CODE};
4040

41-
for (int i = 0; i < 2; i++) {
41+
for (int type : types) {
4242
message_context = 0;
43-
status_code = types[i] == GSS_C_GSS_CODE ? major : minor;
43+
status_code = type == GSS_C_GSS_CODE ? major : minor;
4444

4545
if (!status_code) continue;
4646
do {
47-
maj_status = gss_display_status(&min_status, status_code, types[i],
47+
maj_status = gss_display_status(&min_status, status_code, type,
4848
GSS_C_NO_OID, &message_context, &status);
4949
if (maj_status) break;
5050

0 commit comments

Comments
 (0)