Skip to content

Commit b4eb29e

Browse files
committed
Bug#37471922: Auto-fix clang-tidy warnings [22/n] [noclose]
Generate fixes for a number of warnings that clang-tidy can fix automatically. This commit fixes the warning 'readability-string-compare'. Change example: - if (sout.compare(sin) != 0) { + if (sout != sin) { Change-Id: I6c557138f77a12f1cbc4b5b906041d270c962fb9
1 parent 4ef375d commit b4eb29e

16 files changed

+38
-46
lines changed

client/mysqltest.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -5642,7 +5642,7 @@ static bool validate_bug_number_argument(std::string bug_number) {
56425642

56435643
// Check if string representing a bug number starts 'BUG' keyword.
56445644
// Note: This keyword is case-inseinsitive.
5645-
if (bug_number.substr(0, 3).compare("bug") != 0) return false;
5645+
if (bug_number.substr(0, 3) != "bug") return false;
56465646

56475647
// Check if the string contains '#' after 'BUG' keyword
56485648
if (bug_number.at(3) != '#') return false;

client/mysqltest/error_names.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ static st_error global_error_names[] = {
3333

3434
int get_errcode_from_name(std::string error_name) {
3535
for (st_error *error = global_error_names; error->name; error++) {
36-
if (error_name.compare(error->name) == 0) return error->error_code;
36+
if (error_name == error->name) return error->error_code;
3737
}
3838

3939
// Unknown SQL error name, return -1

client/mysqltest/regular_expressions.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ int multi_reg_replace(struct st_replace_regex *r, char *val, size_t *len) {
189189
If some replacement is performed, write the replaced string into the
190190
output buffer.
191191
*/
192-
if (sout.compare(sin) != 0) {
192+
if (sout != sin) {
193193
*len = sout.length();
194194
if (*len >= (uint)*buf_len_p) {
195195
uint need_buf_len = (*len) + 1;

plugin/clone/src/clone_plugin.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ static int match_valid_donor_address(MYSQL_THD thd, const char *host,
266266
transform_lower);
267267

268268
/* Check if input matches with configured host and port. */
269-
if (0 == valid_host.compare(host) && port == valid_port) {
269+
if (host == valid_host && port == valid_port) {
270270
found = true;
271271
}
272272
return (found);

plugin/group_replication/libmysqlgcs/src/bindings/xcom/gcs_xcom_control_interface.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ static bool skip_own_peer_address(
330330

331331
for (const auto &local_node_info_str_ip_entry : my_own_addresses) {
332332
for (auto &peer_rep_ip_entry : peer_rep_ip) {
333-
if (peer_rep_ip_entry.compare(local_node_info_str_ip_entry.first) == 0 &&
333+
if (peer_rep_ip_entry == local_node_info_str_ip_entry.first &&
334334
peer_port == my_own_port) {
335335
// Skip own address if configured in the peer list
336336
return true;

plugin/group_replication/libmysqlgcs/src/bindings/xcom/gcs_xcom_interface.cc

+7-9
Original file line numberDiff line numberDiff line change
@@ -472,9 +472,8 @@ enum_gcs_error Gcs_xcom_interface::configure(
472472

473473
bool should_configure_allowlist = false;
474474
if (ip_allowlist_reconfigure_str) {
475-
should_configure_allowlist =
476-
ip_allowlist_reconfigure_str->compare("on") == 0 ||
477-
ip_allowlist_reconfigure_str->compare("true") == 0;
475+
should_configure_allowlist = *ip_allowlist_reconfigure_str == "on" ||
476+
*ip_allowlist_reconfigure_str == "true";
478477
}
479478

480479
if (should_configure_allowlist) {
@@ -542,8 +541,8 @@ enum_gcs_error Gcs_xcom_interface::configure(
542541
*/
543542
if (bootstrap_group_str != nullptr) {
544543
// Changing bootstrap_group
545-
bool received_boot_param = bootstrap_group_str->compare("on") == 0 ||
546-
bootstrap_group_str->compare("true") == 0;
544+
bool received_boot_param =
545+
*bootstrap_group_str == "on" || *bootstrap_group_str == "true";
547546

548547
m_boot = received_boot_param;
549548
xcom_control->set_boot_node(m_boot);
@@ -960,8 +959,7 @@ bool Gcs_xcom_interface::initialize_xcom(
960959

961960
MYSQL_GCS_LOG_DEBUG("Configured Local member: %s", local_node_str->c_str())
962961

963-
m_boot = bootstrap_group_str->compare("on") == 0 ||
964-
bootstrap_group_str->compare("true") == 0;
962+
m_boot = *bootstrap_group_str == "on" || *bootstrap_group_str == "true";
965963

966964
MYSQL_GCS_LOG_DEBUG("Configured Bootstrap: %s", bootstrap_group_str->c_str())
967965

@@ -1238,7 +1236,7 @@ enum_gcs_error Gcs_xcom_interface::configure_message_stages(
12381236
*/
12391237
const std::string *sptr =
12401238
m_initialization_parameters.get_parameter("compression");
1241-
if (sptr->compare("on") == 0) {
1239+
if (*sptr == "on") {
12421240
compression_threshold = static_cast<unsigned long long>(atoll(
12431241
m_initialization_parameters.get_parameter("compression_threshold")
12441242
->c_str()));
@@ -1249,7 +1247,7 @@ enum_gcs_error Gcs_xcom_interface::configure_message_stages(
12491247
}
12501248

12511249
sptr = m_initialization_parameters.get_parameter("fragmentation");
1252-
if (sptr->compare("on") == 0) {
1250+
if (*sptr == "on") {
12531251
fragmentation_threshold = static_cast<unsigned long long>(atoll(
12541252
m_initialization_parameters.get_parameter("fragmentation_threshold")
12551253
->c_str()));

plugin/group_replication/libmysqlgcs/src/bindings/xcom/gcs_xcom_networking.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ bool get_local_private_addresses(std::map<std::string, int> &out,
246246
std::string ip = it->first;
247247
int cidr = it->second;
248248

249-
if (ip.compare("::1") == 0 || ip.compare(0, 2, "fd") == 0 ||
249+
if (ip == "::1" || ip.compare(0, 2, "fd") == 0 ||
250250
ip.compare(0, 4, "fe80") == 0) {
251251
out.insert(std::make_pair(ip, cidr));
252252
}

plugin/group_replication/libmysqlgcs/src/bindings/xcom/gcs_xcom_utils.cc

+5-6
Original file line numberDiff line numberDiff line change
@@ -198,9 +198,8 @@ void fix_parameters_syntax(Gcs_interface_parameters &interface_params) {
198198

199199
bool should_configure_allowlist = true;
200200
if (ip_allowlist_reconfigure_str) {
201-
should_configure_allowlist =
202-
ip_allowlist_reconfigure_str->compare("on") == 0 ||
203-
ip_allowlist_reconfigure_str->compare("true") == 0;
201+
should_configure_allowlist = *ip_allowlist_reconfigure_str == "on" ||
202+
*ip_allowlist_reconfigure_str == "true";
204203
}
205204

206205
// sets the default ip allowlist
@@ -466,7 +465,7 @@ bool is_parameters_syntax_correct(
466465
}
467466

468467
for (auto &ip_entry : ip) {
469-
if (ip_entry.compare(host) != 0)
468+
if (ip_entry != host)
470469
MYSQL_GCS_LOG_INFO("Translated '" << host << "' to "
471470
<< ip_entry.c_str());
472471
}
@@ -483,7 +482,7 @@ bool is_parameters_syntax_correct(
483482
// see if any IP matches fromt he root namespace
484483
for (it = ips.begin(); it != ips.end() && !matches_local_ip; it++) {
485484
for (auto &ip_entry : ip) {
486-
matches_local_ip = (*it).first.compare(ip_entry) == 0;
485+
matches_local_ip = (*it).first == ip_entry;
487486

488487
if (matches_local_ip) break;
489488
}
@@ -516,7 +515,7 @@ bool is_parameters_syntax_correct(
516515
for (it = namespace_ips.begin();
517516
it != namespace_ips.end() && !matches_local_ip; it++) {
518517
for (auto &ip_entry : ip) {
519-
matches_local_ip = (*it).first.compare(ip_entry) == 0;
518+
matches_local_ip = (*it).first == ip_entry;
520519

521520
if (matches_local_ip) break;
522521
}

plugin/group_replication/libmysqlgcs/src/gcs_interface_factory.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ enum_available_interfaces Gcs_interface_factory::from_string(
100100
std::transform(binding.begin(), binding.end(),
101101
std::back_inserter(binding_to_lower), ::tolower);
102102

103-
if (binding_to_lower.compare("xcom") == 0) retval = XCOM;
103+
if (binding_to_lower == "xcom") retval = XCOM;
104104

105105
return retval;
106106
}

plugin/group_replication/libmysqlgcs/src/interface/gcs_group_identifier.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,6 @@ bool Gcs_group_identifier::operator<(const Gcs_group_identifier &other) const {
3636
}
3737

3838
bool Gcs_group_identifier::operator==(const Gcs_group_identifier &other) const {
39-
return group_id.compare(other.group_id) == 0;
39+
return group_id == other.group_id;
4040
}
4141
/* purecov: end */

plugin/group_replication/libmysqlgcs/src/interface/gcs_member_identifier.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,5 @@ bool Gcs_member_identifier::operator<(
4343

4444
bool Gcs_member_identifier::operator==(
4545
const Gcs_member_identifier &other) const {
46-
return m_member_id.compare(other.m_member_id) == 0;
46+
return m_member_id == other.m_member_id;
4747
}

plugin/group_replication/src/member_info.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -806,7 +806,7 @@ void Group_member_info::set_is_primary_election_running(bool is_running) {
806806

807807
bool Group_member_info::operator==(Group_member_info &other) {
808808
MUTEX_LOCK(lock, &update_lock);
809-
return uuid.compare(other.get_uuid()) == 0;
809+
return uuid == other.get_uuid();
810810
}
811811

812812
const char *Group_member_info::get_member_status_string(

plugin/rewriter/rule.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -180,5 +180,5 @@ Rewrite_result Rule::create_new_query(MYSQL_THD thd) {
180180

181181
bool Rule::matches(MYSQL_THD thd) const {
182182
string normalized_query = services::get_current_query_normalized(thd);
183-
return normalized_query.compare(m_pattern.normalized_pattern) == 0;
183+
return normalized_query == m_pattern.normalized_pattern;
184184
}

unittest/gunit/libmysqlgcs/xcom/gcs_parameters-t.cc

+11-16
Original file line numberDiff line numberDiff line change
@@ -114,14 +114,12 @@ TEST_F(GcsParametersTest, ParametersCompression) {
114114
m_xcs->get_initialization_parameters();
115115

116116
// compression is ON by default
117-
ASSERT_TRUE(init_params.get_parameter("compression")->compare("on") == 0);
117+
ASSERT_TRUE(*init_params.get_parameter("compression") == "on");
118118

119119
// compression_threshold is set to the default
120120
std::stringstream ss;
121121
ss << Gcs_message_stage_lz4::DEFAULT_THRESHOLD;
122-
ASSERT_TRUE(
123-
init_params.get_parameter("compression_threshold")->compare(ss.str()) ==
124-
0);
122+
ASSERT_TRUE(*init_params.get_parameter("compression_threshold") == ss.str());
125123

126124
// finalize the interface
127125
err = m_gcs->finalize();
@@ -152,12 +150,11 @@ TEST_F(GcsParametersTest, ParametersCompression) {
152150
ASSERT_EQ(err, GCS_OK);
153151

154152
// compression is ON by default
155-
ASSERT_TRUE(init_params2.get_parameter("compression")->compare(compression) ==
156-
0);
153+
ASSERT_TRUE(*init_params2.get_parameter("compression") == compression);
157154

158155
// compression is set to the value we explicitly configured
159-
ASSERT_TRUE(init_params2.get_parameter("compression_threshold")
160-
->compare(compression_threshold) == 0);
156+
ASSERT_TRUE(*init_params2.get_parameter("compression_threshold") ==
157+
compression_threshold);
161158

162159
err = m_gcs->finalize();
163160

@@ -189,14 +186,13 @@ TEST_F(GcsParametersTest, ParametersFragmentation) {
189186
m_xcs->get_initialization_parameters();
190187

191188
// fragmentation is ON by default
192-
ASSERT_TRUE(init_params.get_parameter("fragmentation")->compare("on") == 0);
189+
ASSERT_TRUE(*init_params.get_parameter("fragmentation") == "on");
193190

194191
// fragmentation_threshold is set to the default
195192
std::stringstream ss;
196193
ss << Gcs_message_stage_split_v2::DEFAULT_THRESHOLD;
197-
ASSERT_TRUE(
198-
init_params.get_parameter("fragmentation_threshold")->compare(ss.str()) ==
199-
0);
194+
ASSERT_TRUE(*init_params.get_parameter("fragmentation_threshold") ==
195+
ss.str());
200196

201197
// finalize the interface
202198
err = m_gcs->finalize();
@@ -228,12 +224,11 @@ TEST_F(GcsParametersTest, ParametersFragmentation) {
228224
ASSERT_EQ(err, GCS_OK);
229225

230226
// fragmentation is ON by default
231-
ASSERT_TRUE(
232-
init_params2.get_parameter("fragmentation")->compare(fragmentation) == 0);
227+
ASSERT_TRUE(*init_params2.get_parameter("fragmentation") == fragmentation);
233228

234229
// fragmentation is set to the value we explicitly configured
235-
ASSERT_TRUE(init_params2.get_parameter("fragmentation_threshold")
236-
->compare(fragmentation_threshold) == 0);
230+
ASSERT_TRUE(*init_params2.get_parameter("fragmentation_threshold") ==
231+
fragmentation_threshold);
237232

238233
err = m_gcs->finalize();
239234

unittest/gunit/libmysqlgcs/xcom/gcs_xcom_statistics_interface-t.cc

+3-3
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,8 @@ TEST_F(XcomStatisticsTest, SuspiciousCountTest) {
129129

130130
uint32_t node_to_find = 0;
131131
auto find_node_lambda = [&](Gcs_node_suspicious elem) {
132-
return elem.m_node_address.compare(
133-
suspicious_list.at(node_to_find).m_node_address) == 0;
132+
return elem.m_node_address ==
133+
suspicious_list.at(node_to_find).m_node_address;
134134
};
135135

136136
for (; node_to_find < suspicious_list_ret.size(); node_to_find++) {
@@ -142,7 +142,7 @@ TEST_F(XcomStatisticsTest, SuspiciousCountTest) {
142142
}
143143

144144
auto do_not_find_node_lambda = [](Gcs_node_suspicious elem) {
145-
return elem.m_node_address.compare("node6") == 0;
145+
return elem.m_node_address == "node6";
146146
};
147147

148148
auto result_from_find =

unittest/gunit/libmysqlgcs/xcom/gcs_xcom_statistics_manager-t.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ TEST_F(XcomStatisticsManagerTest, AddAndGetMultipleSuspiciousTest) {
127127
std::string node_to_find{"node1"};
128128

129129
auto find_node = [&](Gcs_node_suspicious &elem) {
130-
return elem.m_node_address.compare(node_to_find) == 0;
130+
return elem.m_node_address == node_to_find;
131131
};
132132

133133
auto result1 =

0 commit comments

Comments
 (0)