Skip to content

Commit

Permalink
Fix clang-tidy warning
Browse files Browse the repository at this point in the history
  • Loading branch information
axic authored and chfast committed Apr 5, 2022
1 parent 4b51752 commit 6592eaf
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 17 deletions.
2 changes: 1 addition & 1 deletion test/benchmarks/keccak_benchmarks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <ethash/keccak.h>


void fake_keccakf1600(const uint64_t* state) noexcept
void fake_keccakf1600(uint64_t* state) noexcept // NOLINT(readability-non-const-parameter)
{
// Do nothing to measure performance of the code outside the keccakf function.
(void)state;
Expand Down
12 changes: 6 additions & 6 deletions test/benchmarks/keccak_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@ inline void keccak_default(uint64_t* out, const uint8_t* data, size_t size) noex
static constexpr size_t block_size = (1600 - bits * 2) / 8;
static constexpr size_t block_words = block_size / sizeof(uint64_t);

bool aligned = (uintptr_t)data % 8 == 0;
bool aligned = reinterpret_cast<uintptr_t>(data) % 8 == 0;

uint64_t state[25] = {};

uint64_t block[block_words];

uint64_t* p;
const uint64_t* p = nullptr;

while (size >= block_size)
{
Expand All @@ -82,7 +82,7 @@ inline void keccak_default(uint64_t* out, const uint8_t* data, size_t size) noex
p = block;
}
else
p = (uint64_t*)data;
p = reinterpret_cast<const uint64_t*>(data);
xor_into_state(state, p, block_words);
fake_keccakf1600(state);
data += block_size;
Expand Down Expand Up @@ -141,7 +141,7 @@ inline void keccak_fastest(uint64_t* out, const uint8_t* data, size_t size)

while (size >= sizeof(uint64_t))
{
uint64_t* p_state_word = (uint64_t*)p_state_bytes;
uint64_t* p_state_word = reinterpret_cast<uint64_t*>(p_state_bytes);
*p_state_word ^= load_le(data);
data += sizeof(uint64_t);
size -= sizeof(uint64_t);
Expand All @@ -164,7 +164,7 @@ inline void keccak_fastest(uint64_t* out, const uint8_t* data, size_t size)

void fake_keccak256_default_aligned(uint64_t* out, const uint8_t* data, size_t size) noexcept
{
keccak_default_aligned<256>(out, (uint64_t*)data, size / 8);
keccak_default_aligned<256>(out, reinterpret_cast<const uint64_t*>(data), size / 8);
}

void fake_keccak256_default(uint64_t* out, const uint8_t* data, size_t size) noexcept
Expand All @@ -179,5 +179,5 @@ void fake_keccak256_fastest(uint64_t* out, const uint8_t* data, size_t size) noe

void fake_keccak256_fastest_word4(uint64_t out[4], const uint64_t data[4]) noexcept
{
keccak_fastest(out, (const uint8_t*)data, 32);
keccak_fastest(out, reinterpret_cast<const uint8_t*>(data), 32);
}
2 changes: 1 addition & 1 deletion test/benchmarks/threadsync_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ std::shared_ptr<fake_cache> build_fake_cache(int id) noexcept
static std::shared_ptr<fake_cache> build_sentinel() noexcept
{
static thread_local fake_cache sentinel;
return std::shared_ptr<fake_cache>(&sentinel, [](fake_cache*) {});
return {&sentinel, [](fake_cache* /*unused*/) {}};
}

namespace
Expand Down
4 changes: 3 additions & 1 deletion test/experimental/difficulty.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ inline int clz(uint32_t x) noexcept


extern "C" {
// Reduce complexity of this function and enable `readability-function-cognitive-complexity`
// in clang-tidty.
NO_SANITIZE("unsigned-integer-overflow")
NO_SANITIZE("unsigned-shift-base")
ethash_hash256 ethash_difficulty_to_boundary(const ethash_hash256* difficulty) noexcept
Expand Down Expand Up @@ -144,7 +146,7 @@ ethash_hash256 ethash_difficulty_to_boundary(const ethash_hash256* difficulty) n
}

// Convert to big-endian.
ethash_hash256 boundary;
ethash_hash256 boundary = {};
for (size_t i = 0; i < num_words; ++i)
boundary.word32s[i] = ethash::be::uint32(q[num_words - 1 - i]);
return boundary;
Expand Down
7 changes: 6 additions & 1 deletion test/fakeminer/fakeminer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ namespace
class ethash_interface
{
public:
virtual ~ethash_interface() noexcept = default;
ethash_interface() = default;
virtual ~ethash_interface() = default;
ethash_interface(const ethash_interface&) = delete;
ethash_interface& operator=(const ethash_interface&) = delete;
ethash_interface(ethash_interface&&) = delete;
ethash_interface& operator=(ethash_interface&&) = delete;

virtual void search(
const ethash::hash256& header_hash, uint64_t nonce, size_t iterations) const noexcept = 0;
Expand Down
1 change: 1 addition & 0 deletions test/unittests/test_cases.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ struct hash_test_case
const char* final_hash_hex;
};

// NOLINTNEXTLINE(misc-definitions-in-headers)
hash_test_case hash_test_cases[] = {
{
0,
Expand Down
7 changes: 3 additions & 4 deletions test/unittests/test_ethash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -774,17 +774,16 @@ TEST(ethash, small_dataset)
auto solution = search_light(*context, {}, boundary, 940, 10);
EXPECT_TRUE(solution.solution_found);
EXPECT_EQ(solution.nonce, 948);
auto final_hash_hex = "004b92ceeb2045f9745917e4d9868a0db16b06d60ee1d8d33b9ff859053f4bb8";
const auto final_hash_hex = "004b92ceeb2045f9745917e4d9868a0db16b06d60ee1d8d33b9ff859053f4bb8";
EXPECT_EQ(to_hex(solution.final_hash), final_hash_hex);
auto mix_hash_hex = "a5a4f053b8424f1c0a4403898d106f0488c8a819334c542ac4fabc0d2cbd7f26";
const auto mix_hash_hex = "a5a4f053b8424f1c0a4403898d106f0488c8a819334c542ac4fabc0d2cbd7f26";
EXPECT_EQ(to_hex(solution.mix_hash), mix_hash_hex);

solution = search(*context_full, {}, boundary, 940, 10);
EXPECT_TRUE(solution.solution_found);
EXPECT_EQ(solution.nonce, 948);
final_hash_hex = "004b92ceeb2045f9745917e4d9868a0db16b06d60ee1d8d33b9ff859053f4bb8";
EXPECT_EQ(to_hex(solution.final_hash), final_hash_hex);
mix_hash_hex = "a5a4f053b8424f1c0a4403898d106f0488c8a819334c542ac4fabc0d2cbd7f26";
EXPECT_EQ(to_hex(solution.mix_hash), mix_hash_hex);

solution = search_light(*context, {}, boundary, 483, 10);
EXPECT_FALSE(solution.solution_found);
Expand Down
2 changes: 2 additions & 0 deletions test/unittests/test_global_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ TEST(managed_multithreaded, get_epoch_context_random)
static constexpr int num_threads = 4;

std::vector<std::future<int>> futures;
futures.reserve(num_threads);

for (int i = 0; i < num_threads; ++i)
{
Expand Down Expand Up @@ -141,6 +142,7 @@ TEST(managed_multithreaded, get_epoch_context_full)
static constexpr int num_threads = 4;

std::vector<std::future<bool>> futures;
futures.reserve(num_threads);

for (int i = 0; i < num_threads; ++i)
{
Expand Down
6 changes: 3 additions & 3 deletions test/unittests/test_keccak.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,10 +226,10 @@ TEST(keccak, unaligned)

for (size_t offset = 1; offset < sizeof(uint64_t); ++offset)
{
uint8_t *data = &buffer[offset];
std::memcpy(data, test_text, text_length);
uint8_t* data = &buffer[offset];
std::memcpy(data, test_text, text_length); // NOLINT(bugprone-not-null-terminated-result)

for (auto &t : test_cases)
for (auto& t : test_cases)
{
const auto h256 = keccak256(data, t.input_size);
ASSERT_EQ(to_hex(h256), t.expected_hash256) << t.input_size;
Expand Down

0 comments on commit 6592eaf

Please sign in to comment.