Skip to content

Commit 3f30bc0

Browse files
committed
tidy
Signed-off-by: turuslan <[email protected]>
1 parent 8a2a383 commit 3f30bc0

File tree

3 files changed

+21
-10
lines changed

3 files changed

+21
-10
lines changed

.github/workflows/clang-tidy.yml

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ jobs:
2121
- name: run checks
2222
env:
2323
BUILD_DIR: build
24+
shell: bash
2425
run: |
2526
cmake -B $BUILD_DIR .
2627
cmake --build $BUILD_DIR --target generated

housekeeping/clang-tidy-diff.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@
88
BUILD_DIR="${BUILD_DIR:?}"
99

1010
cd $(dirname $0)/..
11-
git diff -U0 origin/master | clang-tidy-diff.py -p1 -path $BUILD_DIR
11+
git diff -U0 origin/master | clang-tidy-diff.py -p1 -path $BUILD_DIR -iregex '(include|src)\/.*\.(h|c|hpp|cpp)'

src/multi/converters/converter_utils.cpp

+19-9
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,28 @@
2424
#include <libp2p/multi/multibase_codec/codecs/base58.hpp>
2525
#include <libp2p/multi/uvarint.hpp>
2626

27+
// TODO: CLANG-TIDY TEST
28+
2729
// TODO(turuslan): qtils, https://github.com/qdrvm/kagome/issues/1813
2830
namespace qtils {
2931
inline std::string_view byte2str(const libp2p::BytesIn &s) {
30-
// NOLINT(cppcoreguidelines-pro-type-reinterpret-cast)
32+
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
3133
return {reinterpret_cast<const char *>(s.data()), s.size()};
3234
}
3335
} // namespace qtils
3436

3537
// https://github.com/multiformats/rust-multiaddr/blob/3c7e813c3b1fdd4187a9ca9ff67e10af0e79231d/src/protocol.rs#L613-L622
3638
inline void percentEncode(std::string &out, std::string_view str) {
37-
constexpr uint32_t mask[4]{0xffffffff, 0xd000802d, 0x00000000, 0xa8000001};
38-
for (auto &c : str) {
39-
if ((mask[c / 32] & (1 << (c % 32))) != 0) {
39+
constexpr std::array<uint32_t, 4> mask{
40+
0xffffffff,
41+
0xd000802d,
42+
0x00000000,
43+
0xa8000001,
44+
};
45+
for (const auto &c : str) {
46+
if (static_cast<unsigned char>(c) > 0x7f
47+
// NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-constant-array-index)
48+
or (mask[c / 32] & (1 << (c % 32))) != 0) {
4049
fmt::format_to(std::back_inserter(out), "%{:02X}", c);
4150
} else {
4251
out += c;
@@ -63,12 +72,12 @@ inline std::string percentDecode(std::string_view str) {
6372
if (str[0] == '%' and str.size() >= 3) {
6473
auto x1 = f(str[1]), x2 = f(str[2]);
6574
if (x1 and x2) {
66-
out += (*x1 << 4) | *x2;
75+
out.push_back((*x1 << 4) | *x2);
6776
str.remove_prefix(3);
6877
continue;
6978
}
7079
}
71-
out += str[0];
80+
out.push_back(str[0]);
7281
str.remove_prefix(1);
7382
}
7483
return out;
@@ -228,9 +237,10 @@ namespace libp2p::multi::converters {
228237
case Protocol::Code::DNS_ADDR: {
229238
OUTCOME_TRY(data, read_uvar());
230239
auto name = qtils::byte2str(data);
231-
auto i = std::find_if_not(name.begin(), name.end(), [](auto c) {
232-
return std::isalnum(c) || c == '-' || c == '.';
233-
});
240+
const auto *i =
241+
std::find_if_not(name.begin(), name.end(), [](auto c) {
242+
return std::isalnum(c) || c == '-' || c == '.';
243+
});
234244
if (i != name.end()) {
235245
return ConversionError::INVALID_ADDRESS;
236246
}

0 commit comments

Comments
 (0)