From cb6dad0bc4d03e77fdb548b49bf757558c8886ad Mon Sep 17 00:00:00 2001 From: Sergey Kuznetsov Date: Thu, 23 Jul 2026 14:07:08 +0100 Subject: [PATCH] chore: Fix clang-tidy issues --- include/xrpl/tx/wasm/WasmImportsHelper.h | 12 ++---------- include/xrpl/tx/wasm/WasmiVM.h | 2 +- src/libxrpl/tx/wasm/WasmiVM.cpp | 9 ++++++--- src/test/app/HostFuncImpl_test.cpp | 23 +++++++++++++---------- 4 files changed, 22 insertions(+), 24 deletions(-) diff --git a/include/xrpl/tx/wasm/WasmImportsHelper.h b/include/xrpl/tx/wasm/WasmImportsHelper.h index b5b98f672b..0c31e969c1 100644 --- a/include/xrpl/tx/wasm/WasmImportsHelper.h +++ b/include/xrpl/tx/wasm/WasmImportsHelper.h @@ -45,11 +45,7 @@ WasmImpArgs(WasmImportFunc& e) if constexpr (N < C) { using at = boost::mpl::at_c::type; - if constexpr (std::is_pointer_v) - { - e.params.push_back(WasmTypes::WtI32); - } - else if constexpr (std::is_same_v) + if constexpr (std::is_pointer_v || std::is_same_v) { e.params.push_back(WasmTypes::WtI32); } @@ -73,11 +69,7 @@ template void WasmImpRet(WasmImportFunc& e) { - if constexpr (std::is_pointer_v) - { - e.result = WasmTypes::WtI32; - } - else if constexpr (std::is_same_v) + if constexpr (std::is_pointer_v || std::is_same_v) { e.result = WasmTypes::WtI32; } diff --git a/include/xrpl/tx/wasm/WasmiVM.h b/include/xrpl/tx/wasm/WasmiVM.h index d4a026ff54..5a72cd35f6 100644 --- a/include/xrpl/tx/wasm/WasmiVM.h +++ b/include/xrpl/tx/wasm/WasmiVM.h @@ -264,7 +264,7 @@ public: return instanceWrap_.getFunc(funcName, exportTypes_); } - wasm_functype_t* + wasm_functype_t const* getFuncType(std::string_view funcName) const; Wmem diff --git a/src/libxrpl/tx/wasm/WasmiVM.cpp b/src/libxrpl/tx/wasm/WasmiVM.cpp index a174124208..cfe54fccc2 100644 --- a/src/libxrpl/tx/wasm/WasmiVM.cpp +++ b/src/libxrpl/tx/wasm/WasmiVM.cpp @@ -311,7 +311,10 @@ InstanceWrapper::setTransferLimit(std::int64_t x) ModulePtr ModuleWrapper::init(StorePtr& s, Bytes const& wasmBin, beast::Journal j) { - wasm_byte_vec_t const code{.size = wasmBin.size(), .data = (char*)(wasmBin.data())}; + wasm_byte_vec_t const code{ + .size = wasmBin.size(), + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-const-cast) + .data = const_cast(reinterpret_cast(wasmBin.data()))}; ModulePtr m = ModulePtr(wasm_module_new(s.get(), &code), &wasm_module_delete); if (!m) throw std::runtime_error("can't create module"); @@ -482,7 +485,7 @@ ModuleWrapper::buildImports(StorePtr& s, ImportVec const& imports) const return wimports; } -wasm_functype_t* +wasm_functype_t const* ModuleWrapper::getFuncType(std::string_view funcName) const { for (size_t i = 0; i < exportTypes_.size(); i++) @@ -493,7 +496,7 @@ ModuleWrapper::getFuncType(std::string_view funcName) const if (wasm_externtype_kind(exnType) == WASM_EXTERN_FUNC && funcName == std::string_view(name->data, name->size)) { - return wasm_externtype_as_functype(const_cast(exnType)); + return wasm_externtype_as_functype_const(exnType); } } diff --git a/src/test/app/HostFuncImpl_test.cpp b/src/test/app/HostFuncImpl_test.cpp index 378d6a0947..8311aae638 100644 --- a/src/test/app/HostFuncImpl_test.cpp +++ b/src/test/app/HostFuncImpl_test.cpp @@ -3452,7 +3452,7 @@ struct HostFuncImpl_test : public beast::unit_test::Suite BEAST_EXPECT(result[0].of.i32 == 0)) { auto const messages = sink.messages().str(); - BEAST_EXPECT(messages.find(msg) != std::string::npos); + BEAST_EXPECT(messages.contains(msg)); } } @@ -3471,8 +3471,8 @@ struct HostFuncImpl_test : public beast::unit_test::Suite std::string hex; hex.reserve(data.size() * 2); boost::algorithm::hex(data.begin(), data.end(), std::back_inserter(hex)); - BEAST_EXPECT(messages.find(msg) != std::string::npos); - BEAST_EXPECT(messages.find(hex) != std::string::npos); + BEAST_EXPECT(messages.contains(msg)); + BEAST_EXPECT(messages.contains(hex)); } } } @@ -3542,8 +3542,8 @@ struct HostFuncImpl_test : public beast::unit_test::Suite BEAST_EXPECT(result[0].of.i32 == 0)) { auto const messages = sink.messages().str(); - BEAST_EXPECT(messages.find(msg) != std::string::npos); - BEAST_EXPECT(messages.find(std::to_string(num)) != std::string::npos); + BEAST_EXPECT(messages.contains(msg)); + BEAST_EXPECT(messages.contains(std::to_string(num))); } } @@ -3611,8 +3611,8 @@ struct HostFuncImpl_test : public beast::unit_test::Suite BEAST_EXPECT(result[0].of.i32 == 0)) { auto const messages = sink.messages().str(); - BEAST_EXPECT(messages.find(msg) != std::string::npos); - BEAST_EXPECT(messages.find(env.master.human()) != std::string::npos); + BEAST_EXPECT(messages.contains(msg)); + BEAST_EXPECT(messages.contains(env.master.human())); } } @@ -3689,8 +3689,8 @@ struct HostFuncImpl_test : public beast::unit_test::Suite BEAST_EXPECT(result[0].of.i32 == 0)) { auto const messages = sink.messages().str(); - BEAST_EXPECT(messages.find(msg) != std::string::npos); - BEAST_EXPECT(messages.find(amount.getFullText()) != std::string::npos); + BEAST_EXPECT(messages.contains(msg)); + BEAST_EXPECT(messages.contains(amount.getFullText())); } } @@ -6176,7 +6176,10 @@ struct HostFuncImpl_test : public beast::unit_test::Suite // trace() uses getDataString() -> getDataSlice() which does NOT check transfer limit std::string testMsg = "This message is longer than 10 bytes to prove slices don't count"; vrt.setBytes(0, testMsg.data(), testMsg.size()); - vrt.setBytes(100, (uint8_t const*)"dummy", 5); // Empty data slice for trace + vrt.setBytes( + 100, + reinterpret_cast("dummy"), + 5); // Empty data slice for trace { WasmValVec params(5), result(1); // trace(msg_ptr, msg_len, data_ptr, data_len, asHex)