From cafd868773165602505c58a0aa5d5a0d9347d802 Mon Sep 17 00:00:00 2001 From: SChernykh Date: Tue, 8 Dec 2020 12:16:59 +0100 Subject: [PATCH] Fixed errors found by static analysis --- src/backend/common/WorkerJob.h | 2 +- src/backend/cpu/platform/HwlocCpuInfo.h | 2 +- .../opencl/runners/OclAstroBWTRunner.cpp | 2 +- .../opencl/runners/OclKawPowRunner.cpp | 7 ++++-- src/base/crypto/keccak.cpp | 2 +- src/crypto/astrobwt/AstroBWT.cpp | 2 +- src/crypto/cn/r/CryptonightR_gen.cpp | 2 +- src/crypto/randomx/jit_compiler_x86.cpp | 22 +++---------------- src/crypto/randomx/superscalar.cpp | 2 +- src/net/JobResults.cpp | 1 + 10 files changed, 16 insertions(+), 28 deletions(-) diff --git a/src/backend/common/WorkerJob.h b/src/backend/common/WorkerJob.h index a37a05fa..cf664f87 100644 --- a/src/backend/common/WorkerJob.h +++ b/src/backend/common/WorkerJob.h @@ -110,7 +110,7 @@ private: alignas(16) uint8_t m_blobs[2][Job::kMaxBlobSize * N]{}; Job m_jobs[2]; uint32_t m_rounds[2] = { 0, 0 }; - uint64_t m_nonce_mask[2]; + uint64_t m_nonce_mask[2] = { 0, 0 }; uint64_t m_sequence = 0; uint8_t m_index = 0; }; diff --git a/src/backend/cpu/platform/HwlocCpuInfo.h b/src/backend/cpu/platform/HwlocCpuInfo.h index 1a24f425..6a07a037 100644 --- a/src/backend/cpu/platform/HwlocCpuInfo.h +++ b/src/backend/cpu/platform/HwlocCpuInfo.h @@ -46,7 +46,7 @@ public: HwlocCpuInfo(); ~HwlocCpuInfo() override; - static inline bool has(Feature feature) { return m_features & feature; } + static inline bool hasFeature(Feature feature) { return m_features & feature; } inline const std::vector &nodeset() const { return m_nodeset; } inline hwloc_topology_t topology() const { return m_topology; } diff --git a/src/backend/opencl/runners/OclAstroBWTRunner.cpp b/src/backend/opencl/runners/OclAstroBWTRunner.cpp index 71d3637e..33b95e45 100644 --- a/src/backend/opencl/runners/OclAstroBWTRunner.cpp +++ b/src/backend/opencl/runners/OclAstroBWTRunner.cpp @@ -93,7 +93,7 @@ xmrig::OclAstroBWTRunner::~OclAstroBWTRunner() OclLib::release(m_tmp_indices); OclLib::release(m_filtered_hashes); - delete m_bwt_data_sizes_host; + delete [] m_bwt_data_sizes_host; } diff --git a/src/backend/opencl/runners/OclKawPowRunner.cpp b/src/backend/opencl/runners/OclKawPowRunner.cpp index b9ba17fc..fcc0058b 100644 --- a/src/backend/opencl/runners/OclKawPowRunner.cpp +++ b/src/backend/opencl/runners/OclKawPowRunner.cpp @@ -43,6 +43,9 @@ namespace xmrig { +constexpr size_t BLOB_SIZE = 40; + + OclKawPowRunner::OclKawPowRunner(size_t index, const OclLaunchData &data) : OclBaseRunner(index, data) { switch (data.thread.worksize()) @@ -82,7 +85,7 @@ void OclKawPowRunner::run(uint32_t nonce, uint32_t *hashOutput) const size_t global_work_offset = nonce; const size_t global_work_size = m_intensity - (m_intensity % m_workGroupSize); - enqueueWriteBuffer(m_input, CL_FALSE, 0, 40, m_blob); + enqueueWriteBuffer(m_input, CL_FALSE, 0, BLOB_SIZE, m_blob); const uint32_t zero[2] = {}; enqueueWriteBuffer(m_output, CL_FALSE, 0, sizeof(uint32_t), zero); @@ -177,7 +180,7 @@ void OclKawPowRunner::set(const Job &job, uint8_t *blob) OclLib::setKernelArg(m_searchKernel, 5, sizeof(m_stop), &m_stop); m_blob = blob; - enqueueWriteBuffer(m_input, CL_TRUE, 0, sizeof(m_blob), m_blob); + enqueueWriteBuffer(m_input, CL_TRUE, 0, BLOB_SIZE, m_blob); } diff --git a/src/base/crypto/keccak.cpp b/src/base/crypto/keccak.cpp index f7940dfb..6d7f093f 100644 --- a/src/base/crypto/keccak.cpp +++ b/src/base/crypto/keccak.cpp @@ -168,7 +168,7 @@ typedef uint64_t state_t[25]; void xmrig::keccak(const uint8_t *in, int inlen, uint8_t *md, int mdlen) { state_t st; - uint8_t temp[144]; + alignas(8) uint8_t temp[144]; int i, rsiz, rsizw; rsiz = sizeof(state_t) == mdlen ? HASH_DATA_AREA : 200 - 2 * mdlen; diff --git a/src/crypto/astrobwt/AstroBWT.cpp b/src/crypto/astrobwt/AstroBWT.cpp index 2dd701d3..2286a5fe 100644 --- a/src/crypto/astrobwt/AstroBWT.cpp +++ b/src/crypto/astrobwt/AstroBWT.cpp @@ -173,7 +173,7 @@ void sort_indices(int N, const uint8_t* v, uint64_t* indices, uint64_t* tmp_indi bool xmrig::astrobwt::astrobwt_dero(const void* input_data, uint32_t input_size, void* scratchpad, uint8_t* output_hash, int stage2_max_size, bool avx2) { - uint8_t key[32]; + alignas(8) uint8_t key[32]; uint8_t* scratchpad_ptr = (uint8_t*)(scratchpad) + 64; uint8_t* stage1_output = scratchpad_ptr; uint8_t* stage2_output = scratchpad_ptr; diff --git a/src/crypto/cn/r/CryptonightR_gen.cpp b/src/crypto/cn/r/CryptonightR_gen.cpp index 30f72363..e6a61967 100644 --- a/src/crypto/cn/r/CryptonightR_gen.cpp +++ b/src/crypto/cn/r/CryptonightR_gen.cpp @@ -76,7 +76,7 @@ static inline void add_random_math(uint8_t* &p, const V4_Instruction* code, int void_func begin = instructions[c]; - if ((ASM = xmrig::Assembly::BULLDOZER) && (inst.opcode == MUL) && !is_64_bit) { + if ((ASM == xmrig::Assembly::BULLDOZER) && (inst.opcode == MUL) && !is_64_bit) { // AMD Bulldozer has latency 4 for 32-bit IMUL and 6 for 64-bit IMUL // Always use 32-bit IMUL for AMD Bulldozer in 32-bit mode - skip prefix 0x48 and change 0x49 to 0x41 uint8_t* prefix = reinterpret_cast(begin); diff --git a/src/crypto/randomx/jit_compiler_x86.cpp b/src/crypto/randomx/jit_compiler_x86.cpp index 4d5d0ee1..e8fe3d8e 100644 --- a/src/crypto/randomx/jit_compiler_x86.cpp +++ b/src/crypto/randomx/jit_compiler_x86.cpp @@ -411,30 +411,14 @@ namespace randomx { emitByte(instr.getImm32() & 63, code, codePos); break; case randomx::SuperscalarInstructionType::IADD_C7: - emit(REX_81, code, codePos); - emitByte(0xc0 + instr.dst, code, codePos); - emit32(instr.getImm32(), code, codePos); - break; - case randomx::SuperscalarInstructionType::IXOR_C7: - emit(REX_XOR_RI, code, codePos); - emitByte(0xf0 + instr.dst, code, codePos); - emit32(instr.getImm32(), code, codePos); - break; case randomx::SuperscalarInstructionType::IADD_C8: - emit(REX_81, code, codePos); - emitByte(0xc0 + instr.dst, code, codePos); - emit32(instr.getImm32(), code, codePos); - break; - case randomx::SuperscalarInstructionType::IXOR_C8: - emit(REX_XOR_RI, code, codePos); - emitByte(0xf0 + instr.dst, code, codePos); - emit32(instr.getImm32(), code, codePos); - break; case randomx::SuperscalarInstructionType::IADD_C9: emit(REX_81, code, codePos); emitByte(0xc0 + instr.dst, code, codePos); emit32(instr.getImm32(), code, codePos); break; + case randomx::SuperscalarInstructionType::IXOR_C7: + case randomx::SuperscalarInstructionType::IXOR_C8: case randomx::SuperscalarInstructionType::IXOR_C9: emit(REX_XOR_RI, code, codePos); emitByte(0xf0 + instr.dst, code, codePos); @@ -1088,7 +1072,7 @@ namespace randomx { pos += 14; if (jmp_offset >= -128) { - *(uint32_t*)(p + pos) = 0x74 + (jmp_offset << 8); + *(uint32_t*)(p + pos) = 0x74 + (static_cast(jmp_offset) << 8); pos += 2; } else { diff --git a/src/crypto/randomx/superscalar.cpp b/src/crypto/randomx/superscalar.cpp index 2eca929f..c7f500f7 100644 --- a/src/crypto/randomx/superscalar.cpp +++ b/src/crypto/randomx/superscalar.cpp @@ -196,7 +196,7 @@ namespace randomx { int latency_; int resultOp_ = 0; int dstOp_ = 0; - int srcOp_; + int srcOp_ = 0; SuperscalarInstructionInfo(const char* name) : name_(name), type_(SuperscalarInstructionType::INVALID), latency_(0) {} diff --git a/src/net/JobResults.cpp b/src/net/JobResults.cpp index 36ed7b12..4040cd9a 100644 --- a/src/net/JobResults.cpp +++ b/src/net/JobResults.cpp @@ -123,6 +123,7 @@ static void getResults(JobBundle &bundle, std::vector &results, uint3 RxDataset *dataset = Rx::dataset(bundle.job, 0); if (dataset == nullptr) { errors += bundle.nonces.size(); + delete memory; return; }