diff --git a/include/xrpl/tx/wasm/WasmiVM.h b/include/xrpl/tx/wasm/WasmiVM.h index 034f115ee6..61bbedfd1a 100644 --- a/include/xrpl/tx/wasm/WasmiVM.h +++ b/include/xrpl/tx/wasm/WasmiVM.h @@ -273,7 +273,7 @@ private: FuncInfo getFunc(std::string_view funcName) const; - std::vector + static std::vector convertParams(std::vector const& params); static int diff --git a/src/libxrpl/basics/Number.cpp b/src/libxrpl/basics/Number.cpp index 72c129ac7d..5ec9da315e 100644 --- a/src/libxrpl/basics/Number.cpp +++ b/src/libxrpl/basics/Number.cpp @@ -983,7 +983,7 @@ ln(Number const& x, int iterations = 50) for (int i = 1; i <= iterations; ++i) { - sum = sum + z / (2 * i - 1); + sum = sum + z / ((2 * i) - 1); z = z * zz; } diff --git a/src/libxrpl/tx/wasm/HostFuncImplFloat.cpp b/src/libxrpl/tx/wasm/HostFuncImplFloat.cpp index ea810f59d7..0b31bcd6ce 100644 --- a/src/libxrpl/tx/wasm/HostFuncImplFloat.cpp +++ b/src/libxrpl/tx/wasm/HostFuncImplFloat.cpp @@ -39,7 +39,7 @@ public: } uint64_t const v = SerialIter(data).get64(); - if (!(v & STAmount::cIssuedCurrency)) + if ((v & STAmount::cIssuedCurrency) == 0u) return; int32_t const e = static_cast((v >> encodedMantissaBits) & 0xFFull); @@ -47,9 +47,9 @@ public: if (decodedExponent < wasmMinExponent || decodedExponent > wasmMaxExponent) return; - int64_t const neg = (v & STAmount::cPositive) ? 1 : -1; + int64_t const neg = ((v & STAmount::cPositive) != 0u) ? 1 : -1; int64_t const m = neg * static_cast(v & ((1ull << encodedMantissaBits) - 1)); - if (!m) + if (m == 0) return; Number x(makeNumber(m, decodedExponent)); @@ -120,7 +120,7 @@ public: v |= STAmount::cIssuedCurrency; uint64_t const absM = std::abs(m); - if (!absM) + if (absM == 0u) { return floatNull; } @@ -450,7 +450,7 @@ floatPowerImpl(Slice const& x, int32_t n, int32_t mode) detail::Number2 xx(x); if (!xx) return Unexpected(HostFunctionError::FLOAT_INPUT_MALFORMED); - if (xx == Number() && !n) + if (xx == Number() && (n == 0)) return Unexpected(HostFunctionError::INVALID_PARAMS); detail::Number2 res(power(xx, n, 1)); diff --git a/src/libxrpl/tx/wasm/HostFuncImplGetter.cpp b/src/libxrpl/tx/wasm/HostFuncImplGetter.cpp index 7d96c111e8..67542ac559 100644 --- a/src/libxrpl/tx/wasm/HostFuncImplGetter.cpp +++ b/src/libxrpl/tx/wasm/HostFuncImplGetter.cpp @@ -24,7 +24,7 @@ getIntBytes(STBase const* obj) static Expected getAnyFieldData(STBase const* obj) { - if (!obj) + if (obj == nullptr) return Unexpected(HostFunctionError::FIELD_NOT_FOUND); auto const stype = obj->getSType(); @@ -117,13 +117,14 @@ getAnyFieldData(FieldValue const& variantObj) static inline bool noField(STBase const* field) { - return !field || (STI_NOTPRESENT == field->getSType()) || (STI_UNKNOWN == field->getSType()); + return (field == nullptr) || (STI_NOTPRESENT == field->getSType()) || + (STI_UNKNOWN == field->getSType()); } static Expected locateField(STObject const& obj, Slice const& locator) { - if (locator.empty() || (locator.size() & 3)) // must be multiple of 4 + if (locator.empty() || ((locator.size() & 3) != 0u)) // must be multiple of 4 return Unexpected(HostFunctionError::LOCATOR_MALFORMED); static_assert(maxWasmParamLength % sizeof(int32_t) == 0); @@ -133,7 +134,7 @@ locateField(STObject const& obj, Slice const& locator) { uintptr_t const p = reinterpret_cast(locator.data()); - if (p & (alignof(int32_t) - 1)) + if ((p & (alignof(int32_t) - 1)) != 0u) { // unaligned memcpy(&locBuf[0], locator.data(), locator.size()); } diff --git a/src/libxrpl/tx/wasm/HostFuncWrapper.cpp b/src/libxrpl/tx/wasm/HostFuncWrapper.cpp index 83453d9068..6003aefd84 100644 --- a/src/libxrpl/tx/wasm/HostFuncWrapper.cpp +++ b/src/libxrpl/tx/wasm/HostFuncWrapper.cpp @@ -21,19 +21,19 @@ setData( uint8_t const* src, int32_t srcSize) { - if (!srcSize) + if (srcSize == 0) return 0; // LCOV_EXCL_LINE - if (dst < 0 || dstSize < 0 || !src || srcSize < 0) + if (dst < 0 || dstSize < 0 || (src == nullptr) || srcSize < 0) return HfErrorToInt(HostFunctionError::INVALID_PARAMS); if (srcSize > maxWasmDataLength) return HfErrorToInt(HostFunctionError::DATA_FIELD_TOO_LARGE); - auto const memory = runtime ? runtime->getMem() : wmem(); + auto const memory = (runtime != nullptr) ? runtime->getMem() : wmem(); // LCOV_EXCL_START - if (!memory.s) + if (memory.s == 0u) return HfErrorToInt(HostFunctionError::NO_MEM_EXPORTED); // LCOV_EXCL_STOP if ((int64_t)dst + dstSize > memory.s) @@ -339,7 +339,7 @@ checkGas(void* env) HostFunctions* hf = reinterpret_cast(udata->first); auto const* runtime = reinterpret_cast(hf->getRT()); - if (!runtime) + if (runtime == nullptr) { wasm_trap_t* trap = reinterpret_cast( WasmEngine::instance().newTrap("hf no runtime")); // LCOV_EXCL_LINE @@ -1409,7 +1409,7 @@ trace_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results) return hfResult(results, HostFunctionError::INVALID_PARAMS); } - return returnResult(runtime, params, results, hf->trace(*msg, *data, *asHex), index); + return returnResult(runtime, params, results, hf->trace(*msg, *data, *asHex != 0), index); } wasm_trap_t* diff --git a/src/libxrpl/tx/wasm/WasmiVM.cpp b/src/libxrpl/tx/wasm/WasmiVM.cpp index 7dd4b5debc..8147f84588 100644 --- a/src/libxrpl/tx/wasm/WasmiVM.cpp +++ b/src/libxrpl/tx/wasm/WasmiVM.cpp @@ -24,10 +24,10 @@ print_wasm_error(std::string_view msg, wasm_trap_t* trap, beast::Journal jlog) { wasm_byte_vec_t error_message WASM_EMPTY_VEC; - if (trap) + if (trap != nullptr) wasm_trap_message(trap, &error_message); - if (error_message.size) + if (error_message.size != 0u) { j << "WASMI Error: " << msg << ", " << std::string_view(error_message.data, error_message.size - 1); @@ -37,11 +37,11 @@ print_wasm_error(std::string_view msg, wasm_trap_t* trap, beast::Journal jlog) j << "WASMI Error: " << msg; } - if (error_message.size) + if (error_message.size != 0u) wasm_byte_vec_delete(&error_message); } - if (trap) + if (trap != nullptr) wasm_trap_delete(trap); #ifdef DEBUG_OUTPUT @@ -64,7 +64,7 @@ InstanceWrapper::init( InstancePtr mi = InstancePtr( wasm_instance_new(s.get(), m.get(), &imports.vec_, &trap), &wasm_instance_delete); - if (!mi || trap) + if (!mi || (trap != nullptr)) { print_wasm_error("can't create instance", trap, j); throw std::runtime_error("can't create instance"); @@ -126,7 +126,7 @@ InstanceWrapper::getFunc(std::string_view funcName, WasmExporttypeVec const& exp if (!instance_) throw std::runtime_error("no instance"); // LCOV_EXCL_LINE - if (!exportTypes.vec_.size) + if (exportTypes.vec_.size == 0u) throw std::runtime_error("no export"); // LCOV_EXCL_LINE if (exportTypes.vec_.size != exports_.vec_.size) throw std::runtime_error("invalid export"); // LCOV_EXCL_LINE @@ -152,7 +152,7 @@ InstanceWrapper::getFunc(std::string_view funcName, WasmExporttypeVec const& exp } } - if (!f || !ft) + if ((f == nullptr) || (ft == nullptr)) throw std::runtime_error("can't find function <" + std::string(funcName) + ">"); return {f, ft}; @@ -180,7 +180,7 @@ InstanceWrapper::getMem() const } } - if (!mem) + if (mem == nullptr) return {}; // LCOV_EXCL_LINE return {reinterpret_cast(wasm_memory_data(mem)), wasm_memory_data_size(mem)}; @@ -189,7 +189,7 @@ InstanceWrapper::getMem() const std::int64_t InstanceWrapper::getGas() const { - if (!store_) + if (store_ == nullptr) return -1; // LCOV_EXCL_LINE std::uint64_t gas = 0; wasm_store_get_fuel(store_, &gas); @@ -199,13 +199,13 @@ InstanceWrapper::getGas() const std::int64_t InstanceWrapper::setGas(std::int64_t gas) const { - if (!store_) + if (store_ == nullptr) return -1; // LCOV_EXCL_LINE if (gas < 0) gas = std::numeric_limits::max(); wasmi_error_t* err = wasm_store_set_fuel(store_, static_cast(gas)); - if (err) + if (err != nullptr) { // LCOV_EXCL_START print_wasm_error("Can't set instance gas", nullptr, j_); @@ -284,7 +284,7 @@ static WasmValtypeVec makeImpParams(WasmImportFunc const& imp) { auto const paramSize = imp.params.size(); - if (!paramSize) + if (paramSize == 0u) return {}; WasmValtypeVec v(paramSize); @@ -338,7 +338,7 @@ ModuleWrapper::buildImports(StorePtr& s, ImportVec const& imports) const WasmImporttypeVec importTypes; wasm_module_imports(module_.get(), &importTypes.vec_); - if (!importTypes.vec_.size) + if (importTypes.vec_.size == 0u) return {}; if (imports.empty()) throw std::runtime_error("Missing imports"); @@ -388,7 +388,7 @@ ModuleWrapper::buildImports(StorePtr& s, ImportVec const& imports) const reinterpret_cast(imp.wrap), (void*)&obj, nullptr); - if (!func) + if (func == nullptr) { // LCOV_EXCL_START throw std::runtime_error("can't create import function " + imp.name); @@ -494,7 +494,7 @@ std::unique_ptr WasmiEngine::init() { wasm_config_t* config = wasm_config_new(); - if (!config) + if (config == nullptr) { return std::unique_ptr{ nullptr, &wasm_engine_delete}; // LCOV_EXCL_LINE @@ -537,7 +537,7 @@ WasmiEngine::addModule( if (gas < 0) gas = std::numeric_limits::max(); wasmi_error_t* err = wasm_store_set_fuel(store_.get(), static_cast(gas)); - if (err) + if (err != nullptr) { // LCOV_EXCL_START print_wasm_error("Error setting gas", nullptr, j_); @@ -801,7 +801,7 @@ WasmiEngine::runHlp( { throw std::runtime_error("<" + std::string(funcName) + "> failure"); } - if (!res.r.vec_.size) + if (res.r.vec_.size == 0u) { throw std::runtime_error( "<" + std::string(funcName) + "> return nothing"); // LCOV_EXCL_LINE diff --git a/src/test/app/Wasm_test.cpp b/src/test/app/Wasm_test.cpp index 089a6150cf..93add98f3a 100644 --- a/src/test/app/Wasm_test.cpp +++ b/src/test/app/Wasm_test.cpp @@ -62,7 +62,7 @@ uleb128(IT&& it) do { - if (shift > sizeof(std::uint64_t) * 8 - 7) + if (shift > (sizeof(std::uint64_t) * 8) - 7) return {0, 0}; byte = *it++; val |= (byte & 0x7F) << shift; @@ -100,7 +100,7 @@ getSection(Bytes const& module, std::uint8_t n) return {0, 0}; auto [sz, cnt] = uleb128(module.cbegin() + pos); - if (!cnt) + if (cnt == 0u) return {0, 0}; if (pos + cnt + sz > module.size()) return {0, 0};