diff --git a/src/Platform_mac.cpp b/src/Platform_mac.cpp index 936929ab..f054d553 100644 --- a/src/Platform_mac.cpp +++ b/src/Platform_mac.cpp @@ -32,25 +32,25 @@ #include "version.h" #ifdef XMRIG_NVIDIA_PROJECT -# include "nvidia/cryptonight.h" +#include "nvidia/cryptonight.h" #endif -static inline char* createUserAgent() +static inline std::string createUserAgent() { const size_t max = 160; - char* buf = new char[max]; + char buf[max]; -# ifdef XMRIG_NVIDIA_PROJECT +#ifdef XMRIG_NVIDIA_PROJECT const int cudaVersion = cuda_get_runtime_version(); snprintf(buf, max, "%s/%s (Macintosh; Intel Mac OS X) libuv/%s CUDA/%d.%d clang/%d.%d.%d", APP_NAME, APP_VERSION, uv_version_string(), cudaVersion / 1000, cudaVersion % 100, __clang_major__, __clang_minor__, __clang_patchlevel__); -# else +#else snprintf(buf, max, "%s/%s (Macintosh; Intel Mac OS X) libuv/%s clang/%d.%d.%d", APP_NAME, APP_VERSION, uv_version_string(), __clang_major__, __clang_minor__, __clang_patchlevel__); -# endif +#endif return buf; } @@ -58,13 +58,13 @@ static inline char* createUserAgent() void Platform::init(const std::string & userAgent) { - m_userAgent = (userAgent.size() != "") ? userAgent : createUserAgent(); + m_userAgent = (0 < userAgent.size()) ? userAgent : createUserAgent(); } void Platform::release() { - delete [] m_userAgent; + m_userAgent.clear(); } diff --git a/src/Platform_unix.cpp b/src/Platform_unix.cpp index 44b9f0cb..6a0ae64e 100644 --- a/src/Platform_unix.cpp +++ b/src/Platform_unix.cpp @@ -36,7 +36,7 @@ #include "version.h" #ifdef XMRIG_NVIDIA_PROJECT -# include "nvidia/cryptonight.h" +#include "nvidia/cryptonight.h" #endif @@ -44,23 +44,23 @@ static inline std::string createUserAgent() { const size_t max = 160; - char* buf = new char[max]; + char buf[max]; int length = snprintf(buf, max, "%s/%s (Linux ", APP_NAME, APP_VERSION); -# if defined(__x86_64__) +#if defined(__x86_64__) length += snprintf(buf + length, max - length, "x86_64) libuv/%s", uv_version_string()); -# else +#else length += snprintf(buf + length, max - length, "i686) libuv/%s", uv_version_string()); -# endif +#endif -# ifdef XMRIG_NVIDIA_PROJECT +#ifdef XMRIG_NVIDIA_PROJECT const int cudaVersion = cuda_get_runtime_version(); length += snprintf(buf + length, max - length, " CUDA/%d.%d", cudaVersion / 1000, cudaVersion % 100); -# endif +#endif -# ifdef __GNUC__ +#ifdef __GNUC__ length += snprintf(buf + length, max - length, " gcc/%d.%d.%d", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__); -# endif +#endif return buf; } @@ -71,19 +71,15 @@ void Platform::init(const std::string & userAgent) m_userAgent = (0 < userAgent.size()) ? userAgent : createUserAgent(); } - void Platform::release() { m_userAgent.clear(); } - void Platform::setProcessPriority(int priority) { } - - void Platform::setThreadPriority(int priority) { if(priority == -1) @@ -120,7 +116,7 @@ void Platform::setThreadPriority(int priority) setpriority(PRIO_PROCESS, 0, prio); -# ifdef SCHED_IDLE +#ifdef SCHED_IDLE if(priority == 0) { sched_param param; diff --git a/src/net/Client.cpp b/src/net/Client.cpp index 5367e37f..3ae15ad4 100644 --- a/src/net/Client.cpp +++ b/src/net/Client.cpp @@ -485,7 +485,7 @@ void Client::parse(char* line, size_t len) } -void Client::parseNotification(const char* method, const rapidjson::Value & params, +void Client::parseNotification(const std::string & method, const rapidjson::Value & params, const rapidjson::Value & error) { if(error.IsObject()) @@ -498,12 +498,12 @@ void Client::parseNotification(const char* method, const rapidjson::Value & para return; } - if(!method) + if(0 == method.size()) { return; } - if(strcmp(method, "job") == 0) + if(method == "job") { int code = -1; if(parseJob(params, &code)) @@ -522,7 +522,7 @@ void Client::parseResponse(int64_t id, const rapidjson::Value & result, const ra { if(error.IsObject()) { - const char* message = error["message"].GetString(); + const std::string message = error["message"].GetString(); auto it = m_results.find(id); if(it != m_results.end()) @@ -582,8 +582,8 @@ void Client::parseResponse(int64_t id, const rapidjson::Value & result, const ra void Client::ping() { send(snprintf(m_sendBuf, sizeof(m_sendBuf), - "{\"id\":%" PRId64 ",\"jsonrpc\":\"2.0\",\"method\":\"keepalived\",\"params\":{\"id\":\"%s\"}}\n", m_sequence, - m_rpcId)); + "{\"id\":%" PRId64 ",\"jsonrpc\":\"2.0\",\"method\":\"keepalived\",\"params\":{\"id\":\"%s\"}}\n", + m_sequence, m_rpcId)); } diff --git a/src/net/Client.h b/src/net/Client.h index 722947a8..f1cace13 100644 --- a/src/net/Client.h +++ b/src/net/Client.h @@ -120,7 +120,8 @@ private: void prelogin(); void login(); void parse(char* line, size_t len); - void parseNotification(const char* method, const rapidjson::Value & params, const rapidjson::Value & error); + void parseNotification(const std::string & method, const rapidjson::Value & params, + const rapidjson::Value & error); void parseResponse(int64_t id, const rapidjson::Value & result, const rapidjson::Value & error); void ping(); void reconnect();