From 0cc0a4284383e8cb98f26028b4e2d91ca92dbbce Mon Sep 17 00:00:00 2001 From: Victor Fusco <1221933+vfusco@users.noreply.github.com> Date: Wed, 13 Dec 2023 19:25:58 -0300 Subject: [PATCH] fix: lint errors and warnings --- src/Makefile | 10 +++--- src/back-merkle-tree.cpp | 1 + src/complete-merkle-tree.cpp | 2 ++ src/i-hasher.h | 1 - src/machine-merkle-tree.h | 5 ++- src/merkle-tree-proof.h | 8 ++--- src/meta.h | 1 - src/pristine-merkle-tree.cpp | 1 + src/pristine-merkle-tree.h | 2 -- src/protobuf-util.h | 1 - src/server-manager.cpp | 18 +++++++---- src/test-server-manager.cpp | 63 ++++++++++++++++++------------------ 12 files changed, 56 insertions(+), 57 deletions(-) diff --git a/src/Makefile b/src/Makefile index 29560ab..7a9218e 100644 --- a/src/Makefile +++ b/src/Makefile @@ -192,7 +192,7 @@ CLANG_FORMAT_FILES:=$(filter-out %.pb.h,$(strip $(CLANG_FORMAT_FILES))) EMPTY:= SPACE:=$(EMPTY) $(EMPTY) -CLANG_TIDY_HEADER_FILTER=$(PWD)/($(subst $(SPACE),|,$(LINTER_HEADERS))) +CLANG_TIDY_HEADER_FILTER=$(CURDIR)/($(subst $(SPACE),|,$(LINTER_HEADERS))) CXXFLAGS+=$(OPTFLAGS) -std=c++17 -fvisibility=hidden -fPIC -MMD $(CC_MARCH) $(INCS) $(GCFLAGS) $(UBFLAGS) $(DEFS) $(WARNS) $(MYCFLAGS) CFLAGS+=$(OPTFLAGS) -std=c99 -fvisibility=hidden -fPIC -MMD $(CC_MARCH) $(INCS) $(GCFLAGS) $(UBFLAGS) $(DEFS) $(WARNS) $(MYCFLAGS) @@ -353,13 +353,13 @@ test-server-manager: $(TEST_SERVER_MANAGER_OBJS) $(PROTOC) -I$(HEALTHCHECK_DIR) --cpp_out=. $< %.clang-tidy: %.cpp $(PROTO_SOURCES) - @$(CLANG_TIDY) --header-filter='$(CLANG_TIDY_HEADER_FILTER)' $< -- $(CXXFLAGS) 2>/dev/null - @$(CXX) $(CXXFLAGS) $< -MM -MT $@ -MF $@.d > /dev/null 2>&1 + $(CLANG_TIDY) --header-filter='$(CLANG_TIDY_HEADER_FILTER)' $< -- $(CXXFLAGS) 2>/dev/null + $(CXX) $(CXXFLAGS) $< -MM -MT $@ -MF $@.d > /dev/null 2>&1 @touch $@ %.clang-tidy: %.c $(PROTO_SOURCES) - @$(CLANG_TIDY) --header-filter='$(CLANG_TIDY_HEADER_FILTER)' $< -- $(CFLAGS) 2>/dev/null - @$(CC) $(CFLAGS) $< -MM -MT $@ -MF $@.d > /dev/null 2>&1 + $(CLANG_TIDY) --header-filter='$(CLANG_TIDY_HEADER_FILTER)' $< -- $(CFLAGS) 2>/dev/null + $(CC) $(CFLAGS) $< -MM -MT $@ -MF $@.d > /dev/null 2>&1 @touch $@ %.o: %.cpp diff --git a/src/back-merkle-tree.cpp b/src/back-merkle-tree.cpp index e6a55c6..7cfaf7f 100644 --- a/src/back-merkle-tree.cpp +++ b/src/back-merkle-tree.cpp @@ -15,6 +15,7 @@ // #include "back-merkle-tree.h" +#include #include /// \file diff --git a/src/complete-merkle-tree.cpp b/src/complete-merkle-tree.cpp index 62fe1bb..b9ad28e 100644 --- a/src/complete-merkle-tree.cpp +++ b/src/complete-merkle-tree.cpp @@ -16,6 +16,8 @@ #include "complete-merkle-tree.h" +#include + /// \file /// \brief Complete Merkle tree implementation. diff --git a/src/i-hasher.h b/src/i-hasher.h index da26096..ff0e059 100644 --- a/src/i-hasher.h +++ b/src/i-hasher.h @@ -22,7 +22,6 @@ #include #include -#include #include "meta.h" diff --git a/src/machine-merkle-tree.h b/src/machine-merkle-tree.h index c464d0c..6011e97 100644 --- a/src/machine-merkle-tree.h +++ b/src/machine-merkle-tree.h @@ -24,7 +24,6 @@ #include #include #include -#include #include #include "keccak-256-hasher.h" @@ -44,7 +43,7 @@ namespace cartesi { /// /// To optimize for space, subtrees corresponding to pristine /// memory are represented by nullptr nodes. -/// Additionaly, the tree is truncated below *page* nodes +/// Additionally, the tree is truncated below *page* nodes /// subintending LOG2_PAGE_SIZE bits of address space. /// The trees corresponding to pages are rebuilt from the /// original data whenever needed and never stored. @@ -158,7 +157,7 @@ class machine_merkle_tree final { /// \brief Maps a page_index to a node. /// \param page_index Page index. /// \param node Node subintending page. - /// \return 1 if succeeded, 0 othewise. + /// \return 1 if succeeded, 0 otherwise. int set_page_node_map(address_type page_index, tree_node *node); /// \brief Creates and returns a new tree node. diff --git a/src/merkle-tree-proof.h b/src/merkle-tree-proof.h index fe26b46..14df744 100644 --- a/src/merkle-tree-proof.h +++ b/src/merkle-tree-proof.h @@ -20,10 +20,8 @@ /// \file /// \brief Merkle tree proof structure -#include +#include "i-hasher.h" #include -#include -#include #include namespace cartesi { @@ -221,7 +219,7 @@ class merkle_tree_proof final { throw std::out_of_range{"log2_root_size is too large"}; } if (new_log2_target_size < get_log2_target_size()) { - throw std::out_of_range{"log2_taget_size is too small"}; + throw std::out_of_range{"log2_target_size is too small"}; } merkle_tree_proof sliced(new_log2_root_size, new_log2_target_size); hash_type hash = get_target_hash(); @@ -254,7 +252,7 @@ class merkle_tree_proof final { private: /// \brief Converts log2_size to index into siblings array - /// \return Index into siblings array, or throws exception if out of bouds + /// \return Index into siblings array, or throws exception if out of bounds int log2_size_to_index(int log2_size) const { // We know log2_root_size > 0, so log2_root_size-1 >= 0 const int index = m_log2_root_size - 1 - log2_size; diff --git a/src/meta.h b/src/meta.h index e8e6eec..8ca7769 100644 --- a/src/meta.h +++ b/src/meta.h @@ -17,7 +17,6 @@ #ifndef META_H #define META_H -#include #include /// \file diff --git a/src/pristine-merkle-tree.cpp b/src/pristine-merkle-tree.cpp index 1184c62..d1867f6 100644 --- a/src/pristine-merkle-tree.cpp +++ b/src/pristine-merkle-tree.cpp @@ -15,6 +15,7 @@ // #include "pristine-merkle-tree.h" +#include #include /// \file diff --git a/src/pristine-merkle-tree.h b/src/pristine-merkle-tree.h index 5e2092e..b668dbe 100644 --- a/src/pristine-merkle-tree.h +++ b/src/pristine-merkle-tree.h @@ -17,12 +17,10 @@ #ifndef PRISTINE_MERKLE_TREE_H #define PRISTINE_MERKLE_TREE_H -#include #include #include #include "keccak-256-hasher.h" -#include "meta.h" /// \file /// \brief Pristine Merkle tree interface. diff --git a/src/protobuf-util.h b/src/protobuf-util.h index 103abc4..68938f7 100644 --- a/src/protobuf-util.h +++ b/src/protobuf-util.h @@ -20,7 +20,6 @@ #pragma GCC diagnostic ignored "-Wdeprecated-copy" #pragma GCC diagnostic ignored "-Wtype-limits" #include "cartesi-machine.pb.h" -#include "versioning.pb.h" #pragma GCC diagnostic pop #include "machine-merkle-tree.h" diff --git a/src/server-manager.cpp b/src/server-manager.cpp index a61088a..6fea746 100644 --- a/src/server-manager.cpp +++ b/src/server-manager.cpp @@ -14,16 +14,20 @@ // limitations under the License. // +#if defined(__clang__) && defined(__APPLE__) +#if !defined(__ENVIRONMENT_OS_VERSION_MIN_REQUIRED__) && defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) +#define __ENVIRONMENT_OS_VERSION_MIN_REQUIRED__ __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ +#endif +#endif + #include #include #include #include #include -#include #include #include #include -#include #include #include #include @@ -178,7 +182,7 @@ static std::string request_metadata(const grpc::ServerContext &context) { // The idea is as follows: // 1) Completion queue returns tag-1 identifying an server call // 2) Processing of tag-1 starts the appropriate client call -// using stub->Async() and reader->Finish(), and specifes tag-2 for +// using stub->Async() and reader->Finish(), and specifies tag-2 for // completion // 4) Completion queue returns tag-2 identifying the client call is complete // 5) Processing of tag-2 passes result back using write->Finish(), and @@ -459,7 +463,7 @@ class auto_lock final { } } - /// \brief Desctructor automatically releases lock + /// \brief Destructor automatically releases lock ~auto_lock() { m_lock = false; } @@ -1996,7 +2000,7 @@ static std::string read_memory_range(async_context &actx, const MemoryRangeConfi return data ? std::move(*data) : std::string{}; } -/// \brief Checkes if all values are null +/// \brief Checks if all values are null /// \param begin First element /// \param end One past last element /// \return True if all are null, false otherwie @@ -2399,7 +2403,7 @@ static void process_pending_query(handler_context &hctx, async_context &actx, ep set_htif_yield_ack_data(actx, ROLLUP_INSPECT_STATE); auto max_mcycle = actx.session.current_mcycle + actx.session.server_cycles.max_inspect_state; // Loop getting reports until the machine exceeds max_mcycle, rejects the query, accepts the query, - // or behaves inaproppriately + // or behaves inappropriately q.status = completion_status::accepted; auto start_time = std::chrono::system_clock::now(); auto current_mcycle = actx.session.current_mcycle; @@ -2509,7 +2513,7 @@ static void process_pending_inputs(handler_context &hctx, async_context &actx, e check_htif_yield_ack_data(actx, ROLLUP_ADVANCE_STATE); auto max_mcycle = actx.session.current_mcycle + actx.session.server_cycles.max_advance_state; // Loop getting vouchers and notices until the machine exceeds - // max_mcycle, rejects the input, accepts the input, or behaves inaproppriately + // max_mcycle, rejects the input, accepts the input, or behaves inappropriately auto start_time = std::chrono::system_clock::now(); auto mcycle_increment = actx.session.server_cycles.advance_state_increment; auto deadline_increment = actx.session.server_deadline.advance_state_increment; diff --git a/src/test-server-manager.cpp b/src/test-server-manager.cpp index 72b5f2f..a3a8607 100644 --- a/src/test-server-manager.cpp +++ b/src/test-server-manager.cpp @@ -47,7 +47,6 @@ #pragma clang diagnostic pop #endif -#include "back-merkle-tree.h" #include "complete-merkle-tree.h" using CartesiMachine::Void; @@ -508,7 +507,7 @@ static void init_valid_advance_state_request(AdvanceStateRequest &request, const input_metadata->set_input_index(input_index); auto *input_payload = request.mutable_input_payload(); - *input_payload = get_voucher_payload(input_index); // NOLINT: suppres crytopp warnings + *input_payload = get_voucher_payload(input_index); // NOLINT: suppress crytopp warnings } static void init_valid_inspect_state_request(InspectStateRequest &request, const std::string &session_id, @@ -516,7 +515,7 @@ static void init_valid_inspect_state_request(InspectStateRequest &request, const request.set_session_id(session_id); auto *query_payload = request.mutable_query_payload(); - *query_payload = get_report_payload(input); // NOLINT: suppres crytopp warnings + *query_payload = get_report_payload(input); // NOLINT: suppress crytopp warnings } static void init_valid_finish_epoch_request(FinishEpochRequest &epoch_request, const std::string &session_id, @@ -537,8 +536,8 @@ static void assert_status(Status &status, const std::string &rpcname, bool expec throw std::runtime_error("Call to " + rpcname + " failed. Code: " + std::to_string(status.error_code()) + " Message: " + status.error_message() + ". Assert at " + file + ":" + std::to_string(line)); } - throw std::runtime_error("Call to " + rpcname + " succeded when was expected to fail. Assert at " + file + ":" + - std::to_string(line)); + throw std::runtime_error("Call to " + rpcname + " succeeded when was expected to fail. Assert at " + file + + ":" + std::to_string(line)); } } @@ -1014,7 +1013,7 @@ static void validate_finish_epoch_response(FinishEpochResponse &response, uint64 cartesi::complete_merkle_tree notices_tree{LOG2_ROOT_SIZE, LOG2_KECCAK_SIZE, LOG2_KECCAK_SIZE}; assemble_output_epoch_trees(response, vouchers_tree, notices_tree, input_count, skipped); - // Chech vouchers and notices epoch root hashes + // Check vouchers and notices epoch root hashes ASSERT(get_proto_hash(response.vouchers_epoch_root_hash()) == vouchers_tree.get_root_hash(), "Received vouchers epoch root hash should match the calculated one"); ASSERT(get_proto_hash(response.notices_epoch_root_hash()) == notices_tree.get_root_hash(), @@ -1214,7 +1213,7 @@ static void test_advance_state(const std::function