Fix some code bugs

This commit is contained in:
enWILLYado 2018-03-12 22:58:55 +01:00
parent 82da84d849
commit 9b68f187f9
4 changed files with 26 additions and 29 deletions

View file

@ -36,11 +36,11 @@
#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
const int cudaVersion = cuda_get_runtime_version();
@ -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();
}

View file

@ -44,7 +44,7 @@ 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__)
@ -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)

View file

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

View file

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