From a07b0e595338b1f9fe23bc89664c589c08c1c90a Mon Sep 17 00:00:00 2001 From: XMRig Date: Mon, 14 Aug 2017 09:30:41 +0300 Subject: [PATCH] Fix Visual Studio warnings. --- CMakeLists.txt | 2 ++ src/3rdparty/getopt/getopt.h | 2 +- src/3rdparty/jansson/dump.c | 2 ++ src/3rdparty/jansson/hashtable.c | 2 ++ src/3rdparty/jansson/load.c | 2 +- src/Cpu.cpp | 2 +- src/Cpu.h | 4 ++-- src/Mem.h | 4 ++-- src/Mem_win.cpp | 3 +-- src/Options.cpp | 16 ++++++++-------- src/crypto/CryptoNight_p.h | 6 +++--- src/crypto/c_blake256.c | 2 +- src/log/ConsoleLog.cpp | 8 +++----- src/log/FileLog.cpp | 2 +- src/net/Client.cpp | 8 ++++---- src/net/Job.cpp | 2 +- src/net/Job.h | 6 +++--- src/net/Network.cpp | 1 + src/net/Url.cpp | 2 +- src/net/strategies/FailoverStrategy.cpp | 2 +- src/workers/Hashrate.cpp | 4 ++-- 21 files changed, 43 insertions(+), 39 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f6d189e8..4ac3ae5a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -159,6 +159,8 @@ elseif (CMAKE_CXX_COMPILER_ID MATCHES MSVC) set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /Ox /Ot /Oi /MT /GL") set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Ox /Ot /Oi /MT /GL") + add_definitions(/D_CRT_SECURE_NO_WARNINGS) + add_definitions(/D_CRT_NONSTDC_NO_WARNINGS) elseif (CMAKE_CXX_COMPILER_ID MATCHES Clang) diff --git a/src/3rdparty/getopt/getopt.h b/src/3rdparty/getopt/getopt.h index 0cb88895..bcbff179 100644 --- a/src/3rdparty/getopt/getopt.h +++ b/src/3rdparty/getopt/getopt.h @@ -56,7 +56,7 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#pragma warning(disable:4996); +#pragma warning(disable:4996) #define __GETOPT_H__ diff --git a/src/3rdparty/jansson/dump.c b/src/3rdparty/jansson/dump.c index a23fabb7..a332241d 100644 --- a/src/3rdparty/jansson/dump.c +++ b/src/3rdparty/jansson/dump.c @@ -5,6 +5,8 @@ * it under the terms of the MIT license. See LICENSE for details. */ +#pragma warning(disable:4090) + #ifndef _GNU_SOURCE #define _GNU_SOURCE #endif diff --git a/src/3rdparty/jansson/hashtable.c b/src/3rdparty/jansson/hashtable.c index c819319a..e79f83cd 100644 --- a/src/3rdparty/jansson/hashtable.c +++ b/src/3rdparty/jansson/hashtable.c @@ -5,6 +5,8 @@ * it under the terms of the MIT license. See LICENSE for details. */ +#pragma warning(disable:4334) + #if HAVE_CONFIG_H #include #endif diff --git a/src/3rdparty/jansson/load.c b/src/3rdparty/jansson/load.c index c212489a..6b3d1e25 100644 --- a/src/3rdparty/jansson/load.c +++ b/src/3rdparty/jansson/load.c @@ -1034,8 +1034,8 @@ json_t *json_loadf(FILE *input, size_t flags, json_error_t *error) static int fd_get_func(int *fd) { - uint8_t c; #ifdef HAVE_UNISTD_H + uint8_t c; if (read(*fd, &c, 1) == 1) return c; #endif diff --git a/src/Cpu.cpp b/src/Cpu.cpp index e8f7ee17..2e79b6df 100644 --- a/src/Cpu.cpp +++ b/src/Cpu.cpp @@ -68,7 +68,7 @@ int Cpu::optimalThreadsCount(int algo, bool doubleHash, int maxCpuUsage) } if (((float) count / m_totalThreads * 100) > maxCpuUsage) { - count = ceil((float) m_totalThreads * (maxCpuUsage / 100.0)); + count = (int) ceil((float) m_totalThreads * (maxCpuUsage / 100.0)); } return count < 1 ? 1 : count; diff --git a/src/Cpu.h b/src/Cpu.h index 8b7c3643..9444274d 100644 --- a/src/Cpu.h +++ b/src/Cpu.h @@ -41,8 +41,8 @@ public: static void init(); static void setAffinity(int id, uint64_t mask); - static inline bool hasAES() { return m_flags & AES; } - static inline bool isX64() { return m_flags & X86_64; } + static inline bool hasAES() { return (m_flags & AES) != 0; } + static inline bool isX64() { return (m_flags & X86_64) != 0; } static inline const char *brand() { return m_brand; } static inline int cores() { return m_totalCores; } static inline int l2() { return m_l2_cache; } diff --git a/src/Mem.h b/src/Mem.h index 58b91ac7..050fd8e8 100644 --- a/src/Mem.h +++ b/src/Mem.h @@ -50,8 +50,8 @@ public: static void release(); static inline bool isDoubleHash() { return m_doubleHash; } - static inline bool isHugepagesAvailable() { return m_flags & HugepagesAvailable; } - static inline bool isHugepagesEnabled() { return m_flags & HugepagesEnabled; } + static inline bool isHugepagesAvailable() { return (m_flags & HugepagesAvailable) != 0; } + static inline bool isHugepagesEnabled() { return (m_flags & HugepagesEnabled) != 0; } static inline int flags() { return m_flags; } static inline int threads() { return m_threads; } diff --git a/src/Mem_win.cpp b/src/Mem_win.cpp index f47b6ae4..cfdb501b 100644 --- a/src/Mem_win.cpp +++ b/src/Mem_win.cpp @@ -85,9 +85,8 @@ static BOOL SetLockPagesPrivilege() { static LSA_UNICODE_STRING StringToLsaUnicodeString(LPCTSTR string) { LSA_UNICODE_STRING lsaString; - DWORD dwLen = 0; - dwLen = wcslen(string); + DWORD dwLen = (DWORD) wcslen(string); lsaString.Buffer = (LPWSTR) string; lsaString.Length = (USHORT)((dwLen) * sizeof(WCHAR)); lsaString.MaximumLength = (USHORT)((dwLen + 1) * sizeof(WCHAR)); diff --git a/src/Options.cpp b/src/Options.cpp index 1a1e1c69..e79231d5 100644 --- a/src/Options.cpp +++ b/src/Options.cpp @@ -371,7 +371,7 @@ bool Options::parseArg(int key, uint64_t arg) return false; } - m_retries = arg; + m_retries = (int) arg; break; case 'R': /* --retry-pause */ @@ -380,7 +380,7 @@ bool Options::parseArg(int key, uint64_t arg) return false; } - m_retryPause = arg; + m_retryPause = (int) arg; break; case 't': /* --threads */ @@ -389,7 +389,7 @@ bool Options::parseArg(int key, uint64_t arg) return false; } - m_threads = arg; + m_threads = (int) arg; break; case 'v': /* --av */ @@ -398,7 +398,7 @@ bool Options::parseArg(int key, uint64_t arg) return false; } - m_algoVariant = arg; + m_algoVariant = (int) arg; break; case 1003: /* --donate-level */ @@ -407,7 +407,7 @@ bool Options::parseArg(int key, uint64_t arg) return false; } - m_donateLevel = arg; + m_donateLevel = (int) arg; break; case 1004: /* --max-cpu-usage */ @@ -416,7 +416,7 @@ bool Options::parseArg(int key, uint64_t arg) return false; } - m_maxCpuUsage = arg; + m_maxCpuUsage = (int) arg; break; case 1007: /* --print-time */ @@ -425,7 +425,7 @@ bool Options::parseArg(int key, uint64_t arg) return false; } - m_printTime = arg; + m_printTime = (int) arg; break; case 1020: /* --cpu-affinity */ @@ -609,7 +609,7 @@ bool Options::setAlgo(const char *algo) { for (size_t i = 0; i < ARRAY_SIZE(algo_names); i++) { if (algo_names[i] && !strcmp(algo, algo_names[i])) { - m_algo = i; + m_algo = (int) i; break; } diff --git a/src/crypto/CryptoNight_p.h b/src/crypto/CryptoNight_p.h index a74a4ee0..b85a9da6 100644 --- a/src/crypto/CryptoNight_p.h +++ b/src/crypto/CryptoNight_p.h @@ -311,7 +311,7 @@ static inline void cn_implode_scratchpad(const __m128i *input, __m128i *output) template inline void cryptonight_hash(const void *__restrict__ input, size_t size, void *__restrict__ output, cryptonight_ctx *__restrict__ ctx) { - keccak(static_cast(input), size, ctx->state0, 200); + keccak(static_cast(input), (int) size, ctx->state0, 200); cn_explode_scratchpad((__m128i*) ctx->state0, (__m128i*) ctx->memory); @@ -365,8 +365,8 @@ inline void cryptonight_hash(const void *__restrict__ input, size_t size, void * template inline void cryptonight_double_hash(const void *__restrict__ input, size_t size, void *__restrict__ output, struct cryptonight_ctx *__restrict__ ctx) { - keccak((const uint8_t *) input, size, ctx->state0, 200); - keccak((const uint8_t *) input + size, size, ctx->state1, 200); + keccak((const uint8_t *) input, (int) size, ctx->state0, 200); + keccak((const uint8_t *) input + size, (int) size, ctx->state1, 200); const uint8_t* l0 = ctx->memory; const uint8_t* l1 = ctx->memory + MEM; diff --git a/src/crypto/c_blake256.c b/src/crypto/c_blake256.c index 0b484b94..00a84c22 100644 --- a/src/crypto/c_blake256.c +++ b/src/crypto/c_blake256.c @@ -148,7 +148,7 @@ void blake256_update(state *S, const uint8_t *data, uint64_t datalen) { if (datalen > 0) { memcpy((void *) (S->buf + left), (void *) data, datalen >> 3); - S->buflen = (left << 3) + datalen; + S->buflen = (left << 3) + (int) datalen; } else { S->buflen = 0; } diff --git a/src/log/ConsoleLog.cpp b/src/log/ConsoleLog.cpp index 51e8040a..b641c0e6 100644 --- a/src/log/ConsoleLog.cpp +++ b/src/log/ConsoleLog.cpp @@ -92,8 +92,7 @@ void ConsoleLog::message(int level, const char* fmt, va_list args) } } - const size_t len = 64 + strlen(fmt) + 2; - char *buf = new char[len]; + char *buf = new char[64 + strlen(fmt) + 2]; sprintf(buf, "[%d-%02d-%02d %02d:%02d:%02d]%s %s%s\n", stime.tm_year + 1900, @@ -113,8 +112,7 @@ void ConsoleLog::message(int level, const char* fmt, va_list args) void ConsoleLog::text(const char* fmt, va_list args) { - const int len = 64 + strlen(fmt) + 2; - char *buf = new char[len]; + char *buf = new char[64 + strlen(fmt) + 2]; sprintf(buf, "%s%s\n", fmt, m_colors ? Log::kCL_N : ""); @@ -129,7 +127,7 @@ void ConsoleLog::print(char *fmt, va_list args) uv_buf_t buf; buf.base = strdup(m_buf); - buf.len = strlen(buf.base); + buf.len = (ULONG) strlen(buf.base); uv_write_t *req = new uv_write_t; req->data = buf.base; diff --git a/src/log/FileLog.cpp b/src/log/FileLog.cpp index 224c600d..9a8711a4 100644 --- a/src/log/FileLog.cpp +++ b/src/log/FileLog.cpp @@ -88,7 +88,7 @@ void FileLog::onWrite(uv_fs_t *req) void FileLog::write(char *data, size_t size) { - uv_buf_t buf = uv_buf_init(data, size); + uv_buf_t buf = uv_buf_init(data, (unsigned int) size); uv_fs_t *req = static_cast(malloc(sizeof(uv_fs_t))); req->data = buf.base; diff --git a/src/net/Client.cpp b/src/net/Client.cpp index 2c6e3ba4..a129ddb0 100644 --- a/src/net/Client.cpp +++ b/src/net/Client.cpp @@ -99,7 +99,7 @@ int64_t Client::send(char *data, size_t size) return -1; } - uv_buf_t buf = uv_buf_init(data, size ? size : strlen(data)); + uv_buf_t buf = uv_buf_init(data, (unsigned int) (size ? size : strlen(data))); uv_write_t *req = new uv_write_t; req->data = buf.base; @@ -464,7 +464,7 @@ void Client::reconnect() } m_failures++; - m_listener->onClose(this, m_failures); + m_listener->onClose(this, (int) m_failures); m_expire = uv_now(uv_default_loop()) + m_retryPause; } @@ -501,7 +501,7 @@ void Client::onAllocBuffer(uv_handle_t *handle, size_t suggested_size, uv_buf_t auto client = getClient(handle->data); buf->base = &client->m_recvBuf.base[client->m_recvBufPos]; - buf->len = client->m_recvBuf.len - client->m_recvBufPos; + buf->len = client->m_recvBuf.len - (ULONG) client->m_recvBufPos; } @@ -548,7 +548,7 @@ void Client::onRead(uv_stream_t *stream, ssize_t nread, const uv_buf_t *buf) auto client = getClient(stream->data); if (nread < 0) { if (nread != UV_EOF && !client->m_quiet) { - LOG_ERR("[%s:%u] read error: \"%s\"", client->m_url.host(), client->m_url.port(), uv_strerror(nread)); + LOG_ERR("[%s:%u] read error: \"%s\"", client->m_url.host(), client->m_url.port(), uv_strerror((int) nread)); } return client->close();; diff --git a/src/net/Job.cpp b/src/net/Job.cpp index 4929aaf5..bce65e62 100644 --- a/src/net/Job.cpp +++ b/src/net/Job.cpp @@ -82,7 +82,7 @@ bool Job::setBlob(const char *blob) return false; } - if (!fromHex(blob, m_size * 2, m_blob)) { + if (!fromHex(blob, (int) m_size * 2, m_blob)) { return false; } diff --git a/src/net/Job.h b/src/net/Job.h index e7fca53e..1b2f732a 100644 --- a/src/net/Job.h +++ b/src/net/Job.h @@ -44,9 +44,9 @@ public: inline const char *id() const { return m_id; } inline const uint8_t *blob() const { return m_blob; } inline int poolId() const { return m_poolId; } + inline size_t size() const { return m_size; } inline uint32_t *nonce() { return reinterpret_cast(m_blob + 39); } - inline uint32_t diff() const { return m_diff; } - inline uint32_t size() const { return m_size; } + inline uint32_t diff() const { return (uint32_t) m_diff; } inline uint64_t target() const { return m_target; } inline void setNicehash(bool nicehash) { m_nicehash = nicehash; } @@ -67,7 +67,7 @@ private: int m_poolId; VAR_ALIGN(16, char m_id[64]); VAR_ALIGN(16, uint8_t m_blob[84]); // Max blob size is 84 (75 fixed + 9 variable), aligned to 96. https://github.com/xmrig/xmrig/issues/1 Thanks fireice-uk. - uint32_t m_size; + size_t m_size; uint64_t m_diff; uint64_t m_target; diff --git a/src/net/Network.cpp b/src/net/Network.cpp index 2e6ec298..a5132c73 100644 --- a/src/net/Network.cpp +++ b/src/net/Network.cpp @@ -21,6 +21,7 @@ * along with this program. If not, see . */ +#pragma warning(disable:4244) #include #include diff --git a/src/net/Url.cpp b/src/net/Url.cpp index 82b788d9..a0024d26 100644 --- a/src/net/Url.cpp +++ b/src/net/Url.cpp @@ -121,7 +121,7 @@ bool Url::parse(const char *url) memcpy(m_host, base, size - 1); m_host[size - 1] = '\0'; - m_port = strtol(port, nullptr, 10); + m_port = (uint16_t) strtol(port, nullptr, 10); return true; } diff --git a/src/net/strategies/FailoverStrategy.cpp b/src/net/strategies/FailoverStrategy.cpp index 37afffec..e25b8c58 100644 --- a/src/net/strategies/FailoverStrategy.cpp +++ b/src/net/strategies/FailoverStrategy.cpp @@ -140,7 +140,7 @@ void FailoverStrategy::onResultAccepted(Client *client, int64_t seq, uint32_t di void FailoverStrategy::add(const Url *url, const char *agent) { - Client *client = new Client(m_pools.size(), agent, this); + Client *client = new Client((int) m_pools.size(), agent, this); client->setUrl(url); client->setRetryPause(Options::i()->retryPause() * 1000); diff --git a/src/workers/Hashrate.cpp b/src/workers/Hashrate.cpp index 4c373156..5bc65698 100644 --- a/src/workers/Hashrate.cpp +++ b/src/workers/Hashrate.cpp @@ -127,8 +127,8 @@ double Hashrate::calc(size_t threadId, size_t ms) const } double hashes, time; - hashes = lastestHashCnt - earliestHashCount; - time = lastestStamp - earliestStamp; + hashes = (double) lastestHashCnt - earliestHashCount; + time = (double) lastestStamp - earliestStamp; time /= 1000.0; return hashes / time;