Skip to content

Commit 6023790

Browse files
clang-tidy fixes (#494)
Signed-off-by: Alexey-N-Chernyshov <[email protected]>
1 parent 7cb3333 commit 6023790

Some content is hidden

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

58 files changed

+556
-464
lines changed

core/common/io_thread.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,16 @@ namespace fc {
1515
: io{std::make_shared<boost::asio::io_context>()},
1616
work{io->get_executor()},
1717
thread{[this] { io->run(); }} {}
18+
IoThread(const IoThread &) = delete;
19+
IoThread(IoThread &&) = delete;
1820
inline ~IoThread() {
1921
io->stop();
2022
if (thread.joinable()) {
2123
thread.join();
2224
}
2325
}
26+
IoThread &operator=(const IoThread &) = delete;
27+
IoThread &operator=(IoThread &&) = delete;
2428

2529
std::shared_ptr<boost::asio::io_context> io;
2630
boost::asio::executor_work_guard<boost::asio::io_context::executor_type>

core/common/libp2p/peer/peer_info_helper.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ namespace fc {
5454
const std::string *ip = {}) {
5555
if (auto port{nonZeroPort(addr)}) {
5656
if (isZeroIp(addr)) {
57-
if (ip) {
57+
if (ip != nullptr) {
5858
return Multiaddress::create(fmt::format("/ip4/{}/tcp/{}", *ip, *port))
5959
.value();
6060
}

core/common/libp2p/stream_open_queue.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,14 @@ namespace libp2p::connection {
1919
std::weak_ptr<StreamOpenQueue> weak;
2020
List::iterator it;
2121

22+
Active(const Active &) = delete;
23+
Active(Active &&) = delete;
2224
Active(std::shared_ptr<Stream> stream,
2325
std::weak_ptr<StreamOpenQueue> weak,
2426
List::iterator it);
2527
~Active() override;
28+
Active &operator=(const Active &) = delete;
29+
Active &operator=(Active &&) = delete;
2630
};
2731

2832
struct Pending {

core/config/profile_config.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,16 @@ namespace fc::config {
2020
std::vector<std::string> const &values,
2121
Profile *,
2222
int) {
23-
using namespace boost::program_options;
23+
using boost::program_options::validation_error;
24+
using boost::program_options::validators::check_first_occurrence;
25+
using boost::program_options::validators::get_single_string;
2426

2527
// Make sure no previous assignment to 'v' was made.
26-
validators::check_first_occurrence(v);
28+
check_first_occurrence(v);
2729

2830
// Extract the first string from 'values'. If there is more than
2931
// one string, it's an error, and exception will be thrown.
30-
std::string const &value = validators::get_single_string(values);
32+
std::string const &value = get_single_string(values);
3133
if (value == "mainnet" || value == "2k" || value == "no-upgrades"
3234
|| value == "interopnet") {
3335
v = boost::any(Profile{value});
@@ -36,9 +38,8 @@ namespace fc::config {
3638
}
3739
}
3840

39-
boost::program_options::options_description configProfile() {
40-
boost::program_options::options_description optionsDescription(
41-
"Profile options");
41+
options_description configProfile() {
42+
options_description optionsDescription("Profile options");
4243
optionsDescription.add_options()(
4344
"profile",
4445
boost::program_options::value<Profile>()

core/config/profile_config.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@
88
#include <boost/program_options.hpp>
99

1010
namespace fc::config {
11+
using boost::program_options::options_description;
12+
1113
/**
1214
* Creates program option description for 'profile' and initialize parameters
1315
* according the profile.
1416
*
1517
* @return profile program option description
1618
*/
17-
boost::program_options::options_description configProfile();
19+
options_description configProfile();
1820
} // namespace fc::config

core/crypto/secp256k1/impl/secp256k1_provider_impl.cpp

Lines changed: 43 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,18 @@ namespace fc::crypto::secp256k1 {
4646
const PrivateKey &key) const {
4747
secp256k1_pubkey pubkey;
4848

49-
if (!secp256k1_ec_pubkey_create(context_.get(), &pubkey, key.data())) {
49+
if (secp256k1_ec_pubkey_create(context_.get(), &pubkey, key.data()) == 0) {
5050
return Secp256k1Error::kKeyGenerationFailed;
5151
}
5252

5353
PublicKeyUncompressed public_key{};
5454
size_t outputlen = kPublicKeyUncompressedLength;
55-
if (!secp256k1_ec_pubkey_serialize(context_.get(),
56-
public_key.data(),
57-
&outputlen,
58-
&pubkey,
59-
SECP256K1_EC_UNCOMPRESSED)) {
55+
if (secp256k1_ec_pubkey_serialize(context_.get(),
56+
public_key.data(),
57+
&outputlen,
58+
&pubkey,
59+
SECP256K1_EC_UNCOMPRESSED)
60+
== 0) {
6061
return Secp256k1Error::kPubkeySerializationError;
6162
}
6263

@@ -66,21 +67,23 @@ namespace fc::crypto::secp256k1 {
6667
outcome::result<PublicKeyUncompressed> Secp256k1ProviderImpl::sign(
6768
gsl::span<const uint8_t> message, const PrivateKey &key) const {
6869
secp256k1_ecdsa_recoverable_signature sig_struct;
69-
if (!secp256k1_ecdsa_sign_recoverable(context_.get(),
70-
&sig_struct,
71-
message.data(),
72-
key.cbegin(),
73-
secp256k1_nonce_function_rfc6979,
74-
nullptr)) {
70+
if (secp256k1_ecdsa_sign_recoverable(context_.get(),
71+
&sig_struct,
72+
message.data(),
73+
key.cbegin(),
74+
secp256k1_nonce_function_rfc6979,
75+
nullptr)
76+
== 0) {
7577
return Secp256k1Error::kCannotSignError;
7678
}
7779
SignatureCompact signature{};
7880
int recid = 0;
79-
if (!secp256k1_ecdsa_recoverable_signature_serialize_compact(
80-
context_.get(), signature.data(), &recid, &sig_struct)) {
81+
if (secp256k1_ecdsa_recoverable_signature_serialize_compact(
82+
context_.get(), signature.data(), &recid, &sig_struct)
83+
== 0) {
8184
return Secp256k1Error::kSignatureSerializationError;
8285
}
83-
signature[64] = (uint8_t)recid;
86+
signature[64] = static_cast<uint8_t>(recid);
8487
return signature;
8588
}
8689

@@ -93,16 +96,19 @@ namespace fc::crypto::secp256k1 {
9396
secp256k1_ecdsa_signature sig;
9497
secp256k1_pubkey pubkey;
9598

96-
if (!secp256k1_ecdsa_signature_parse_compact(
97-
context_.get(), &sig, signature.data())) {
99+
if (secp256k1_ecdsa_signature_parse_compact(
100+
context_.get(), &sig, signature.data())
101+
== 0) {
98102
return Secp256k1Error::kSignatureParseError;
99103
}
100-
if (!secp256k1_ec_pubkey_parse(
101-
context_.get(), &pubkey, key.data(), key.size())) {
104+
if (secp256k1_ec_pubkey_parse(
105+
context_.get(), &pubkey, key.data(), key.size())
106+
== 0) {
102107
return Secp256k1Error::kPubkeyParseError;
103108
}
104-
return (secp256k1_ecdsa_verify(
105-
context_.get(), &sig, message.data(), &pubkey) == 1);
109+
return (
110+
secp256k1_ecdsa_verify(context_.get(), &sig, message.data(), &pubkey)
111+
== 1);
106112
}
107113

108114
outcome::result<PublicKeyUncompressed>
@@ -114,29 +120,35 @@ namespace fc::crypto::secp256k1 {
114120
secp256k1_ecdsa_recoverable_signature sig_rec;
115121
secp256k1_pubkey pubkey;
116122

117-
if (!secp256k1_ecdsa_recoverable_signature_parse_compact(
118-
context_.get(), &sig_rec, signature.data(), (int)signature[64])) {
123+
if (secp256k1_ecdsa_recoverable_signature_parse_compact(
124+
context_.get(),
125+
&sig_rec,
126+
signature.data(),
127+
static_cast<int>(signature[64]))
128+
== 0) {
119129
return Secp256k1Error::kSignatureParseError;
120130
}
121-
if (!secp256k1_ecdsa_recover(
122-
context_.get(), &pubkey, &sig_rec, message.data())) {
131+
if (secp256k1_ecdsa_recover(
132+
context_.get(), &pubkey, &sig_rec, message.data())
133+
== 0) {
123134
return Secp256k1Error::kRecoverError;
124135
}
125136
PublicKeyUncompressed pubkey_out;
126137
size_t outputlen = kPublicKeyUncompressedLength;
127-
if (!secp256k1_ec_pubkey_serialize(context_.get(),
128-
pubkey_out.data(),
129-
&outputlen,
130-
&pubkey,
131-
SECP256K1_EC_UNCOMPRESSED)) {
138+
if (secp256k1_ec_pubkey_serialize(context_.get(),
139+
pubkey_out.data(),
140+
&outputlen,
141+
&pubkey,
142+
SECP256K1_EC_UNCOMPRESSED)
143+
== 0) {
132144
return Secp256k1Error::kPubkeySerializationError;
133145
}
134146

135147
return pubkey_out;
136148
}
137149

138150
outcome::result<void> Secp256k1ProviderImpl::checkSignature(
139-
const SignatureCompact &signature) const {
151+
const SignatureCompact &signature) {
140152
if (signature[64] > 3) {
141153
return Secp256k1Error::kSignatureParseError;
142154
}

core/crypto/secp256k1/impl/secp256k1_provider_impl.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ namespace fc::crypto::secp256k1 {
4141
private:
4242
std::unique_ptr<secp256k1_context, void (*)(secp256k1_context *)> context_;
4343

44-
outcome::result<void> checkSignature(
45-
const SignatureCompact &signature) const;
44+
static outcome::result<void> checkSignature(
45+
const SignatureCompact &signature);
4646
};
4747

4848
} // namespace fc::crypto::secp256k1

0 commit comments

Comments
 (0)