Fix Visual Studio warnings.

This commit is contained in:
XMRig
2017-08-14 10:14:29 +03:00
parent 5021615897
commit 422c5f87f6
20 changed files with 38 additions and 451 deletions

View File

@@ -76,8 +76,6 @@ set(SOURCES
if (WIN32)
set(SOURCES_OS
res/app.rc
src/3rdparty/winansi.cpp
src/3rdparty/winansi.h
src/App_win.cpp
src/proxy/Proxy_win.cpp
src/proxy/Uuid_win.cpp
@@ -143,6 +141,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)

View File

@@ -56,7 +56,7 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#pragma warning(disable:4996);
#pragma warning(disable:4996)
#define __GETOPT_H__

View File

@@ -5,6 +5,10 @@
* it under the terms of the MIT license. See LICENSE for details.
*/
#ifdef _MSC_VER
#pragma warning(disable:4090)
#endif
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif

View File

@@ -5,6 +5,10 @@
* it under the terms of the MIT license. See LICENSE for details.
*/
#ifdef _MSC_VER
#pragma warning(disable:4334)
#endif
#if HAVE_CONFIG_H
#include <jansson_private_config.h>
#endif

View File

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

View File

@@ -1,392 +0,0 @@
/**
* Old Git implementation of windows terminal colors (2009)
* before use of a threaded wrapper.
*/
#undef NOGDI
#include <windows.h>
#include <wingdi.h>
#include <winreg.h>
#include <malloc.h>
#include <stdio.h>
#include <io.h>
#include "winansi.h"
/*
* Copyright 2008 Peter Harris <git@peter.is-a-geek.org>
*/
/*
Functions to be wrapped:
*/
#undef printf
#undef fprintf
#undef fputs
#undef vfprintf
/* TODO: write */
/*
ANSI codes used by git: m, K
This file is git-specific. Therefore, this file does not attempt
to implement any codes that are not used by git.
*/
static HANDLE console;
static WORD plain_attr;
static WORD attr;
static int negative;
static void init(void)
{
CONSOLE_SCREEN_BUFFER_INFO sbi;
static int initialized = 0;
if (initialized)
return;
console = GetStdHandle(STD_OUTPUT_HANDLE);
if (console == INVALID_HANDLE_VALUE)
console = NULL;
if (!console)
return;
GetConsoleScreenBufferInfo(console, &sbi);
attr = plain_attr = sbi.wAttributes;
negative = 0;
initialized = 1;
}
static int write_console(const char *str, int len)
{
/* convert utf-8 to utf-16, write directly to console */
int wlen = MultiByteToWideChar(CP_UTF8, 0, str, len, NULL, 0);
wchar_t *wbuf = (wchar_t *)alloca(wlen * sizeof(wchar_t));
MultiByteToWideChar(CP_UTF8, 0, str, len, wbuf, wlen);
WriteConsoleW(console, wbuf, wlen, NULL, NULL);
/* return original (utf-8 encoded) length */
return len;
}
#define FOREGROUND_ALL (FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE)
#define BACKGROUND_ALL (BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE)
static void set_console_attr(void)
{
WORD attributes = attr;
if (negative) {
attributes &= ~FOREGROUND_ALL;
attributes &= ~BACKGROUND_ALL;
/* This could probably use a bitmask
instead of a series of ifs */
if (attr & FOREGROUND_RED)
attributes |= BACKGROUND_RED;
if (attr & FOREGROUND_GREEN)
attributes |= BACKGROUND_GREEN;
if (attr & FOREGROUND_BLUE)
attributes |= BACKGROUND_BLUE;
if (attr & BACKGROUND_RED)
attributes |= FOREGROUND_RED;
if (attr & BACKGROUND_GREEN)
attributes |= FOREGROUND_GREEN;
if (attr & BACKGROUND_BLUE)
attributes |= FOREGROUND_BLUE;
}
SetConsoleTextAttribute(console, attributes);
}
static void erase_in_line(void)
{
CONSOLE_SCREEN_BUFFER_INFO sbi;
DWORD dummy; /* Needed for Windows 7 (or Vista) regression */
if (!console)
return;
GetConsoleScreenBufferInfo(console, &sbi);
FillConsoleOutputCharacterA(console, ' ',
sbi.dwSize.X - sbi.dwCursorPosition.X, sbi.dwCursorPosition,
&dummy);
}
static const char *set_attr(const char *str)
{
const char *func;
size_t len = strspn(str, "0123456789;");
func = str + len;
switch (*func) {
case 'm':
do {
long val = strtol(str, (char **)&str, 10);
switch (val) {
case 0: /* reset */
attr = plain_attr;
negative = 0;
break;
case 1: /* bold */
attr |= FOREGROUND_INTENSITY;
break;
case 2: /* faint */
case 22: /* normal */
attr &= ~FOREGROUND_INTENSITY;
break;
case 3: /* italic */
/* Unsupported */
break;
case 4: /* underline */
case 21: /* double underline */
/* Wikipedia says this flag does nothing */
/* Furthermore, mingw doesn't define this flag
attr |= COMMON_LVB_UNDERSCORE; */
break;
case 24: /* no underline */
/* attr &= ~COMMON_LVB_UNDERSCORE; */
break;
case 5: /* slow blink */
case 6: /* fast blink */
/* We don't have blink, but we do have
background intensity */
attr |= BACKGROUND_INTENSITY;
break;
case 25: /* no blink */
attr &= ~BACKGROUND_INTENSITY;
break;
case 7: /* negative */
negative = 1;
break;
case 27: /* positive */
negative = 0;
break;
case 8: /* conceal */
case 28: /* reveal */
/* Unsupported */
break;
case 30: /* Black */
attr &= ~FOREGROUND_ALL;
break;
case 31: /* Red */
attr &= ~FOREGROUND_ALL;
attr |= FOREGROUND_RED;
break;
case 32: /* Green */
attr &= ~FOREGROUND_ALL;
attr |= FOREGROUND_GREEN;
break;
case 33: /* Yellow */
attr &= ~FOREGROUND_ALL;
attr |= FOREGROUND_RED | FOREGROUND_GREEN;
break;
case 34: /* Blue */
attr &= ~FOREGROUND_ALL;
attr |= FOREGROUND_BLUE;
break;
case 35: /* Magenta */
attr &= ~FOREGROUND_ALL;
attr |= FOREGROUND_RED | FOREGROUND_BLUE;
break;
case 36: /* Cyan */
attr &= ~FOREGROUND_ALL;
attr |= FOREGROUND_GREEN | FOREGROUND_BLUE;
break;
case 37: /* White */
attr |= FOREGROUND_RED |
FOREGROUND_GREEN |
FOREGROUND_BLUE;
break;
case 38: /* Unknown */
break;
case 39: /* reset */
attr &= ~FOREGROUND_ALL;
attr |= (plain_attr & FOREGROUND_ALL);
break;
case 40: /* Black */
attr &= ~BACKGROUND_ALL;
break;
case 41: /* Red */
attr &= ~BACKGROUND_ALL;
attr |= BACKGROUND_RED;
break;
case 42: /* Green */
attr &= ~BACKGROUND_ALL;
attr |= BACKGROUND_GREEN;
break;
case 43: /* Yellow */
attr &= ~BACKGROUND_ALL;
attr |= BACKGROUND_RED | BACKGROUND_GREEN;
break;
case 44: /* Blue */
attr &= ~BACKGROUND_ALL;
attr |= BACKGROUND_BLUE;
break;
case 45: /* Magenta */
attr &= ~BACKGROUND_ALL;
attr |= BACKGROUND_RED | BACKGROUND_BLUE;
break;
case 46: /* Cyan */
attr &= ~BACKGROUND_ALL;
attr |= BACKGROUND_GREEN | BACKGROUND_BLUE;
break;
case 47: /* White */
attr |= BACKGROUND_RED |
BACKGROUND_GREEN |
BACKGROUND_BLUE;
break;
case 48: /* Unknown */
break;
case 49: /* reset */
attr &= ~BACKGROUND_ALL;
attr |= (plain_attr & BACKGROUND_ALL);
break;
default:
/* Unsupported code */
break;
}
str++;
} while (*(str - 1) == ';');
set_console_attr();
break;
case 'K':
erase_in_line();
break;
default:
/* Unsupported code */
break;
}
return func + 1;
}
static int ansi_emulate(const char *str, FILE *stream)
{
int rv = 0;
const char *pos = str;
fflush(stream);
while (*pos) {
pos = strstr(str, "\033[");
if (pos) {
int len = (int) (pos - str);
if (len) {
int out_len = write_console(str, len);
rv += out_len;
if (out_len < len)
return rv;
}
str = pos + 2;
rv += 2;
pos = set_attr(str);
rv += (int) (pos - str);
str = pos;
}
else {
int len = (int) strlen(str);
rv += write_console(str, len);
return rv;
}
}
return rv;
}
int winansi_fputs(const char *str, FILE *stream)
{
int rv;
if (!isatty(fileno(stream)))
return fputs(str, stream);
init();
if (!console)
return fputs(str, stream);
rv = ansi_emulate(str, stream);
if (rv >= 0)
return 0;
else
return EOF;
}
int winansi_vfprintf(FILE *stream, const char *format, va_list list)
{
int len, rv;
char small_buf[256] = { 0 };
char *buf = small_buf;
va_list cp;
if (!isatty(fileno(stream)))
goto abort;
init();
if (!console)
goto abort;
va_copy(cp, list);
len = vsnprintf(small_buf, sizeof(small_buf), format, cp);
#ifdef WIN32
/* bug on long strings without that */
if (len == -1)
len = _vscprintf(format, cp);
#endif
va_end(cp);
if ((unsigned) len > sizeof(small_buf) - 1) {
buf = (char*)malloc(len + 1);
if (!buf)
goto abort;
len = vsnprintf(buf, len + 1, format, list);
#ifdef WIN32
if (len == -1)
len = _vscprintf(format, list);
#endif
}
rv = ansi_emulate(buf, stream);
if (buf != small_buf)
free(buf);
return rv;
abort:
rv = vfprintf(stream, format, list);
return rv;
}
int winansi_fprintf(FILE *stream, const char *format, ...)
{
va_list list;
int rv;
va_start(list, format);
rv = winansi_vfprintf(stream, format, list);
va_end(list);
return rv;
}
int winansi_printf(const char *format, ...)
{
va_list list;
int rv;
va_start(list, format);
rv = winansi_vfprintf(stdout, format, list);
va_end(list);
return rv;
}

View File

@@ -1,29 +0,0 @@
/*
* ANSI emulation wrappers
*/
#include <windows.h>
#include <stddef.h>
#include <stdio.h>
#define fileno(fd) _fileno(fd)
#ifdef __cplusplus
extern "C" {
#endif
int winansi_fputs(const char *str, FILE *stream);
int winansi_printf(const char *format, ...);
int winansi_fprintf(FILE *stream, const char *format, ...);
int winansi_vfprintf(FILE *stream, const char *format, va_list list);
#ifdef __cplusplus
}
#endif
#undef fputs
#undef fprintf
#undef vfprintf
#define fputs winansi_fputs
#define printf winansi_printf
#define fprintf winansi_fprintf
#define vfprintf winansi_vfprintf

View File

@@ -311,7 +311,7 @@ bool Options::parseArg(int key, uint64_t arg)
return false;
}
m_retries = arg;
m_retries = (int) arg;
break;
case 'R': /* --retry-pause */
@@ -320,7 +320,7 @@ bool Options::parseArg(int key, uint64_t arg)
return false;
}
m_retryPause = arg;
m_retryPause = (int) arg;
break;
case 1003: /* --donate-level */
@@ -329,7 +329,7 @@ bool Options::parseArg(int key, uint64_t arg)
return false;
}
m_donateLevel = arg;
m_donateLevel = (int) arg;
break;
default:

View File

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

View File

@@ -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<uv_fs_t*>(malloc(sizeof(uv_fs_t)));
req->data = buf.base;

View File

@@ -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;
@@ -168,7 +168,6 @@ void Client::tick(uint64_t now)
if (m_state == ConnectingState) {
LOG_NOTICE("RECONNECT");
connect();
}
}
@@ -465,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;
}
@@ -502,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;
}
@@ -549,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();;

View File

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

View File

@@ -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<uint32_t*>(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;

View File

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

View File

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

View File

@@ -61,7 +61,7 @@ public:
memcpy(m_host, addr, size - 1);
m_host[size - 1] = '\0';
m_port = strtol(port, nullptr, 10);
m_port = (uint16_t) strtol(port, nullptr, 10);
}

View File

@@ -118,7 +118,7 @@ void Miner::send(char *data)
}
const size_t size = strlen(data);
uv_buf_t buf = uv_buf_init(data, size);
uv_buf_t buf = uv_buf_init(data, (unsigned int) size);
uv_write_t *req = new uv_write_t;
req->data = buf.base;
@@ -308,7 +308,7 @@ void Miner::onAllocBuffer(uv_handle_t *handle, size_t suggested_size, uv_buf_t *
auto miner = getMiner(handle->data);
buf->base = &miner->m_recvBuf.base[miner->m_recvBufPos];
buf->len = miner->m_recvBuf.len - miner->m_recvBufPos;
buf->len = miner->m_recvBuf.len - (ULONG) miner->m_recvBufPos;
}

View File

@@ -21,6 +21,9 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifdef _MSC_VER
#pragma warning(disable:4244)
#endif
#include <ctime>
#include <inttypes.h>

View File

@@ -106,7 +106,7 @@ void NonceSplitter::printConnections()
}
}
const int error = m_upstreams.size() - active - suspended;
const int error = (int) m_upstreams.size() - active - suspended;
double efficiency = (double) Counters::miners() / (active * 256) * 100.0;
LOG_INFO("\x1B[01;32m* \x1B[01;37mupstreams\x1B[0m" LABEL("active") "%s%d\x1B[0m" LABEL("sleep") "\x1B[01;37m%d\x1B[0m" LABEL("error") "%s%d\x1B[0m" LABEL("total") "\x1B[01;37m%d",

View File

@@ -147,13 +147,13 @@ int NonceStorage::nextIndex(int start) const
{
for (size_t i = m_index; i < m_used.size(); ++i) {
if (m_used[i] == 0) {
return i;
return (int) i;
}
}
for (size_t i = start; i < m_index; ++i) {
if (m_used[i] == 0) {
return i;
return (int) i;
}
}