diff --git a/src/3rdparty/fmt/format-inl.h b/src/3rdparty/fmt/format-inl.h index 5ebad7002..b8249f337 100644 --- a/src/3rdparty/fmt/format-inl.h +++ b/src/3rdparty/fmt/format-inl.h @@ -1754,7 +1754,7 @@ inline bool divisible_by_power_of_2(uint64_t x, int exp) FMT_NOEXCEPT { #ifdef FMT_BUILTIN_CTZLL return FMT_BUILTIN_CTZLL(x) >= exp; #else - return exp < num_bits()) && x == ((x >> exp) << exp); + return (exp < num_bits()) && x == ((x >> exp) << exp); #endif } diff --git a/src/backend/opencl/runners/tools/OclKawPow.cpp b/src/backend/opencl/runners/tools/OclKawPow.cpp index 4b8274f4f..15feeb80c 100644 --- a/src/backend/opencl/runners/tools/OclKawPow.cpp +++ b/src/backend/opencl/runners/tools/OclKawPow.cpp @@ -306,7 +306,7 @@ private: } - static std::string merge(std::string a, std::string b, uint32_t r) + static std::string merge(const std::string& a, const std::string& b, uint32_t r) { switch (r % 4) { @@ -323,7 +323,7 @@ private: } - static std::string math(std::string d, std::string a, std::string b, uint32_t r) + static std::string math(const std::string& d, const std::string& a, const std::string& b, uint32_t r) { switch (r % 11) { diff --git a/src/backend/opencl/wrappers/OclLib.cpp b/src/backend/opencl/wrappers/OclLib.cpp index 158ef13e8..4794f36bf 100644 --- a/src/backend/opencl/wrappers/OclLib.cpp +++ b/src/backend/opencl/wrappers/OclLib.cpp @@ -836,7 +836,13 @@ xmrig::String xmrig::OclLib::getProgramBuildLog(cl_program program, cl_device_id return String(); } - char *log = new char[size + 1](); + char* log = nullptr; + try { + log = new char[size + 1](); + } + catch (...) { + return String(); + } if (getProgramBuildInfo(program, device, CL_PROGRAM_BUILD_LOG, size, log, nullptr) != CL_SUCCESS) { delete [] log; diff --git a/src/base/net/tools/LineReader.cpp b/src/base/net/tools/LineReader.cpp index aa2897fc9..07d0f1dc2 100644 --- a/src/base/net/tools/LineReader.cpp +++ b/src/base/net/tools/LineReader.cpp @@ -56,8 +56,8 @@ void xmrig::LineReader::reset() void xmrig::LineReader::add(const char *data, size_t size) { - if (size > XMRIG_NET_BUFFER_CHUNK_SIZE - m_pos) { - // it breakes correctness silently for long lines + if (size + m_pos > XMRIG_NET_BUFFER_CHUNK_SIZE) { + // it breaks correctness silently for long lines return; } diff --git a/src/base/tools/String.cpp b/src/base/tools/String.cpp index cfc8e0404..f001ff8fa 100644 --- a/src/base/tools/String.cpp +++ b/src/base/tools/String.cpp @@ -125,7 +125,7 @@ std::vector xmrig::String::split(char sep) const for (pos = 0; pos < m_size; ++pos) { if (m_data[pos] == sep) { - if ((pos - start) > 0) { + if (pos > start) { out.emplace_back(m_data + start, pos - start); } @@ -133,7 +133,7 @@ std::vector xmrig::String::split(char sep) const } } - if ((pos - start) > 0) { + if (pos > start) { out.emplace_back(m_data + start, pos - start); } diff --git a/src/crypto/common/VirtualMemory_win.cpp b/src/crypto/common/VirtualMemory_win.cpp index 659a94a60..9bee37ffe 100644 --- a/src/crypto/common/VirtualMemory_win.cpp +++ b/src/crypto/common/VirtualMemory_win.cpp @@ -63,7 +63,7 @@ Return value: TRUE indicates success, FALSE failure. static BOOL SetLockPagesPrivilege() { HANDLE token; - if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &token) != TRUE) { + if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &token)) { return FALSE; } @@ -71,12 +71,12 @@ static BOOL SetLockPagesPrivilege() { tp.PrivilegeCount = 1; tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; - if (LookupPrivilegeValue(nullptr, SE_LOCK_MEMORY_NAME, &(tp.Privileges[0].Luid)) != TRUE) { + if (!LookupPrivilegeValue(nullptr, SE_LOCK_MEMORY_NAME, &(tp.Privileges[0].Luid))) { return FALSE; } BOOL rc = AdjustTokenPrivileges(token, FALSE, (PTOKEN_PRIVILEGES) &tp, 0, nullptr, nullptr); - if (rc != TRUE || GetLastError() != ERROR_SUCCESS) { + if (!rc || GetLastError() != ERROR_SUCCESS) { return FALSE; } @@ -101,7 +101,7 @@ static BOOL ObtainLockPagesPrivilege() { HANDLE token; PTOKEN_USER user = nullptr; - if (OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &token) == TRUE) { + if (OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &token)) { DWORD size = 0; GetTokenInformation(token, TokenUser, nullptr, 0, &size); diff --git a/src/crypto/randomx/aes_hash.cpp b/src/crypto/randomx/aes_hash.cpp index 4d0ee7a23..206300fd6 100644 --- a/src/crypto/randomx/aes_hash.cpp +++ b/src/crypto/randomx/aes_hash.cpp @@ -28,6 +28,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include +#include #include "crypto/randomx/aes_hash.hpp" #include "base/tools/Chrono.h" @@ -371,7 +372,7 @@ hashAndFillAes1Rx4_impl* softAESImpl = &hashAndFillAes1Rx4<1,1>; void SelectSoftAESImpl(size_t threadsCount) { constexpr int test_length_ms = 100; - const std::vector impl = { + const std::array impl = { &hashAndFillAes1Rx4<1,1>, &hashAndFillAes1Rx4<2,1>, &hashAndFillAes1Rx4<2,2>, diff --git a/src/crypto/randomx/dataset.hpp b/src/crypto/randomx/dataset.hpp index c15ab3799..da709688a 100644 --- a/src/crypto/randomx/dataset.hpp +++ b/src/crypto/randomx/dataset.hpp @@ -48,7 +48,7 @@ struct randomx_cache { randomx::DatasetInitFunc* datasetInit; randomx::SuperscalarProgram programs[RANDOMX_CACHE_MAX_ACCESSES]; - bool isInitialized() { + bool isInitialized() const { return programs[0].getSize() != 0; } }; diff --git a/src/crypto/randomx/jit_compiler_x86.cpp b/src/crypto/randomx/jit_compiler_x86.cpp index e8fe3d8e4..0307cfd6c 100644 --- a/src/crypto/randomx/jit_compiler_x86.cpp +++ b/src/crypto/randomx/jit_compiler_x86.cpp @@ -1076,7 +1076,7 @@ namespace randomx { pos += 2; } else { - *(uint64_t*)(p + pos) = 0x840f + ((static_cast(jmp_offset) - 4) << 16); + *(uint64_t*)(p + pos) = 0x840f + (static_cast(jmp_offset - 4) << 16); pos += 6; } diff --git a/src/crypto/randomx/jit_compiler_x86.hpp b/src/crypto/randomx/jit_compiler_x86.hpp index 0a9148f97..cc535a0bc 100644 --- a/src/crypto/randomx/jit_compiler_x86.hpp +++ b/src/crypto/randomx/jit_compiler_x86.hpp @@ -68,11 +68,11 @@ namespace randomx { alignas(64) static InstructionGeneratorX86 engine[256]; - int registerUsage[RegistersCount]; - uint8_t* code; - uint32_t codePos; - uint32_t codePosFirst; - uint32_t vm_flags; + int registerUsage[RegistersCount] = {}; + uint8_t* code = nullptr; + uint32_t codePos = 0; + uint32_t codePosFirst = 0; + uint32_t vm_flags = 0; # ifdef XMRIG_FIX_RYZEN std::pair mainLoopBounds; diff --git a/src/crypto/randomx/superscalar.cpp b/src/crypto/randomx/superscalar.cpp index c7f500f75..98c1ea8ec 100644 --- a/src/crypto/randomx/superscalar.cpp +++ b/src/crypto/randomx/superscalar.cpp @@ -282,11 +282,11 @@ namespace randomx { return fetchNextDefault(gen); } private: - const char* name_; - int index_; - const int* counts_; - int opsCount_; - DecoderBuffer() : index_(-1) {} + const char* name_ = nullptr; + int index_ = -1; + const int* counts_ = nullptr; + int opsCount_ = 0; + DecoderBuffer() = default; static const DecoderBuffer decodeBuffer484; static const DecoderBuffer decodeBuffer7333; static const DecoderBuffer decodeBuffer3733; @@ -555,10 +555,10 @@ namespace randomx { const SuperscalarInstructionInfo* info_; int src_ = -1; int dst_ = -1; - int mod_; - uint32_t imm32_; - SuperscalarInstructionType opGroup_; - int opGroupPar_; + int mod_ = 0; + uint32_t imm32_ = 0; + SuperscalarInstructionType opGroup_ = SuperscalarInstructionType::INVALID; + int opGroupPar_ = 0; bool canReuse_ = false; bool groupParIsSource_ = false; diff --git a/src/crypto/randomx/superscalar_program.hpp b/src/crypto/randomx/superscalar_program.hpp index dc173591b..3e40eb2b9 100644 --- a/src/crypto/randomx/superscalar_program.hpp +++ b/src/crypto/randomx/superscalar_program.hpp @@ -39,13 +39,13 @@ namespace randomx { Instruction& operator()(int pc) { return programBuffer[pc]; } - uint32_t getSize() { + uint32_t getSize() const { return size; } void setSize(uint32_t val) { size = val; } - int getAddressRegister() { + int getAddressRegister() const { return addrReg; } void setAddressRegister(int val) { diff --git a/src/crypto/rx/RxQueue.cpp b/src/crypto/rx/RxQueue.cpp index cbbac070c..0c55434d9 100644 --- a/src/crypto/rx/RxQueue.cpp +++ b/src/crypto/rx/RxQueue.cpp @@ -155,7 +155,7 @@ void xmrig::RxQueue::backgroundInit() m_storage->init(item.seed, item.threads, item.hugePages, item.oneGbPages, item.mode, item.priority); - lock = std::unique_lock(m_mutex); + lock.lock(); if (m_state == STATE_SHUTDOWN || !m_queue.empty()) { continue; diff --git a/src/crypto/rx/Rx_linux.cpp b/src/crypto/rx/Rx_linux.cpp index 1525f99de..34a097bb9 100644 --- a/src/crypto/rx/Rx_linux.cpp +++ b/src/crypto/rx/Rx_linux.cpp @@ -103,7 +103,7 @@ static bool wrmsr_on_cpu(uint32_t reg, uint32_t cpu, uint64_t value, uint64_t ma char msr_file_name[64]{}; - sprintf(msr_file_name, "/dev/cpu/%d/msr", cpu); + sprintf(msr_file_name, "/dev/cpu/%u/msr", cpu); int fd = open(msr_file_name, O_WRONLY); if (fd < 0) { return false;