More static analysis fixes

This commit is contained in:
SChernykh 2020-12-08 16:05:58 +01:00
parent cafd868773
commit 0da3390d09
14 changed files with 40 additions and 33 deletions

View file

@ -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);

View file

@ -28,6 +28,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <thread>
#include <vector>
#include <array>
#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<hashAndFillAes1Rx4_impl *> impl = {
const std::array<hashAndFillAes1Rx4_impl *, 4> impl = {
&hashAndFillAes1Rx4<1,1>,
&hashAndFillAes1Rx4<2,1>,
&hashAndFillAes1Rx4<2,2>,

View file

@ -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;
}
};

View file

@ -1076,7 +1076,7 @@ namespace randomx {
pos += 2;
}
else {
*(uint64_t*)(p + pos) = 0x840f + ((static_cast<int64_t>(jmp_offset) - 4) << 16);
*(uint64_t*)(p + pos) = 0x840f + (static_cast<uint64_t>(jmp_offset - 4) << 16);
pos += 6;
}

View file

@ -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<const void*, const void*> mainLoopBounds;

View file

@ -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;

View file

@ -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) {

View file

@ -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<std::mutex>(m_mutex);
lock.lock();
if (m_state == STATE_SHUTDOWN || !m_queue.empty()) {
continue;

View file

@ -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;