mirror of
https://github.com/XRPLF/rippled.git
synced 2026-08-19 05:10:55 +00:00
clang-tidy fixes
This commit is contained in:
@@ -273,7 +273,7 @@ private:
|
||||
FuncInfo
|
||||
getFunc(std::string_view funcName) const;
|
||||
|
||||
std::vector<wasm_val_t>
|
||||
static std::vector<wasm_val_t>
|
||||
convertParams(std::vector<WasmParam> const& params);
|
||||
|
||||
static int
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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<int32_t>((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<int64_t>(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));
|
||||
|
||||
@@ -24,7 +24,7 @@ getIntBytes(STBase const* obj)
|
||||
static Expected<Bytes, HostFunctionError>
|
||||
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<FieldValue, HostFunctionError>
|
||||
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<uintptr_t>(locator.data());
|
||||
if (p & (alignof(int32_t) - 1))
|
||||
if ((p & (alignof(int32_t) - 1)) != 0u)
|
||||
{ // unaligned
|
||||
memcpy(&locBuf[0], locator.data(), locator.size());
|
||||
}
|
||||
|
||||
@@ -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<HostFunctions*>(udata->first);
|
||||
|
||||
auto const* runtime = reinterpret_cast<InstanceWrapper const*>(hf->getRT());
|
||||
if (!runtime)
|
||||
if (runtime == nullptr)
|
||||
{
|
||||
wasm_trap_t* trap = reinterpret_cast<wasm_trap_t*>(
|
||||
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*
|
||||
|
||||
@@ -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<std::uint8_t*>(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<decltype(gas)>::max();
|
||||
wasmi_error_t* err = wasm_store_set_fuel(store_, static_cast<std::uint64_t>(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<wasm_func_callback_with_env_t>(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<wasm_engine_t, decltype(&wasm_engine_delete)>
|
||||
WasmiEngine::init()
|
||||
{
|
||||
wasm_config_t* config = wasm_config_new();
|
||||
if (!config)
|
||||
if (config == nullptr)
|
||||
{
|
||||
return std::unique_ptr<wasm_engine_t, decltype(&wasm_engine_delete)>{
|
||||
nullptr, &wasm_engine_delete}; // LCOV_EXCL_LINE
|
||||
@@ -537,7 +537,7 @@ WasmiEngine::addModule(
|
||||
if (gas < 0)
|
||||
gas = std::numeric_limits<decltype(gas)>::max();
|
||||
wasmi_error_t* err = wasm_store_set_fuel(store_.get(), static_cast<std::uint64_t>(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
|
||||
|
||||
@@ -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};
|
||||
|
||||
Reference in New Issue
Block a user