Skip to content
This repository was archived by the owner on Apr 24, 2022. It is now read-only.

Commit 0dfc700

Browse files
jean-m-cyrXhmikosR
authored andcommittedJun 15, 2018
Fix a bunch of coverity warnings
Some of these address warnings that are not really bugs, but could be. These don't correct logic errors or affect performance, but cost nothing to eliminate. Others, like passing large vars by value have an effect on performance.
1 parent 6d2c9ec commit 0dfc700

File tree

12 files changed

+65
-59
lines changed

12 files changed

+65
-59
lines changed
 

‎ethminer/main.cpp

+25-26
Original file line numberDiff line numberDiff line change
@@ -858,47 +858,46 @@ class MinerCLI
858858

859859
int main(int argc, char** argv)
860860
{
861-
// Set env vars controlling GPU driver behavior.
862-
setenv("GPU_MAX_HEAP_SIZE", "100");
863-
setenv("GPU_MAX_ALLOC_PERCENT", "100");
864-
setenv("GPU_SINGLE_ALLOC_PERCENT", "100");
861+
try {
862+
// Set env vars controlling GPU driver behavior.
863+
setenv("GPU_MAX_HEAP_SIZE", "100");
864+
setenv("GPU_MAX_ALLOC_PERCENT", "100");
865+
setenv("GPU_SINGLE_ALLOC_PERCENT", "100");
865866

866-
MinerCLI m;
867+
MinerCLI m;
867868

868-
m.ParseCommandLine(argc, argv);
869+
m.ParseCommandLine(argc, argv);
869870

870-
if (getenv("SYSLOG"))
871-
g_logSyslog = true;
872-
if (g_logSyslog || (getenv("NO_COLOR")))
873-
g_logNoColor = true;
871+
if (getenv("SYSLOG"))
872+
g_logSyslog = true;
873+
if (g_logSyslog || (getenv("NO_COLOR")))
874+
g_logNoColor = true;
874875
#if defined(_WIN32)
875-
if (!g_logNoColor)
876-
{
877-
g_logNoColor = true;
878-
// Set output mode to handle virtual terminal sequences
879-
// Only works on Windows 10, but most users should use it anyway
880-
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
881-
if (hOut != INVALID_HANDLE_VALUE)
876+
if (!g_logNoColor)
882877
{
883-
DWORD dwMode = 0;
884-
if (GetConsoleMode(hOut, &dwMode))
878+
g_logNoColor = true;
879+
// Set output mode to handle virtual terminal sequences
880+
// Only works on Windows 10, but most users should use it anyway
881+
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
882+
if (hOut != INVALID_HANDLE_VALUE)
885883
{
886-
dwMode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING;
887-
if (SetConsoleMode(hOut, dwMode))
888-
g_logNoColor = false;
884+
DWORD dwMode = 0;
885+
if (GetConsoleMode(hOut, &dwMode))
886+
{
887+
dwMode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING;
888+
if (SetConsoleMode(hOut, dwMode))
889+
g_logNoColor = false;
890+
}
889891
}
890892
}
891-
}
892893
#endif
893894

894-
try
895-
{
896895
m.execute();
897896
}
898897
catch (std::exception& ex)
899898
{
900899
cerr << "Error: " << ex.what() << "\n\n";
901-
return 1;
900+
return -1;
902901
}
903902

904903
return 0;

‎libdevcore/Log.cpp

+21-15
Original file line numberDiff line numberDiff line change
@@ -91,22 +91,28 @@ void dev::setThreadName(char const* _n)
9191

9292
void dev::simpleDebugOut(std::string const& _s)
9393
{
94-
if (!g_logNoColor)
95-
{
96-
std::cerr << _s + '\n';
97-
return;
94+
try {
95+
if (!g_logNoColor)
96+
{
97+
std::cerr << _s + '\n';
98+
return;
99+
}
100+
bool skip = false;
101+
std::stringstream ss;
102+
for (auto it : _s)
103+
{
104+
if (!skip && it == '\x1b')
105+
skip = true;
106+
else if (skip && it == 'm')
107+
skip = false;
108+
else if (!skip)
109+
ss << it;
110+
}
111+
ss << '\n';
112+
std::cerr << ss.str();
98113
}
99-
bool skip = false;
100-
std::stringstream ss;
101-
for (auto it : _s)
114+
catch(...)
102115
{
103-
if (!skip && it == '\x1b')
104-
skip = true;
105-
else if (skip && it == 'm')
106-
skip = false;
107-
else if (!skip)
108-
ss << it;
116+
return;
109117
}
110-
ss << '\n';
111-
std::cerr << ss.str();
112118
}

‎libethash-cuda/CUDAMiner.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -166,14 +166,14 @@ void CUDAMiner::setDevices(const vector<unsigned>& _devices, unsigned _selectedD
166166

167167
unsigned CUDAMiner::getNumDevices()
168168
{
169-
int deviceCount = -1;
169+
int deviceCount;
170170
cudaError_t err = cudaGetDeviceCount(&deviceCount);
171171
if (err == cudaSuccess)
172172
return deviceCount;
173173

174174
if (err == cudaErrorInsufficientDriver)
175175
{
176-
int driverVersion = -1;
176+
int driverVersion;
177177
cudaDriverGetVersion(&driverVersion);
178178
if (driverVersion == 0)
179179
throw std::runtime_error{"No CUDA driver found"};

‎libethash-cuda/CUDAMiner.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,11 @@ class CUDAMiner: public Miner
102102
hash128_t* m_dag = nullptr;
103103
std::vector<hash64_t*> m_light;
104104
int m_dag_size = -1;
105-
uint32_t m_device_num;
105+
uint32_t m_device_num = 0;
106106

107-
volatile search_results** m_search_buf;
108-
cudaStream_t * m_streams;
109-
uint64_t m_current_target;
107+
volatile search_results** m_search_buf = nullptr;
108+
cudaStream_t* m_streams = nullptr;
109+
uint64_t m_current_target = 0;
110110

111111
/// The local work size for the search
112112
static unsigned s_blockSize;

‎libethcore/Farm.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ namespace eth
5151
class Farm: public FarmFace
5252
{
5353
public:
54-
unsigned tstart, tstop;
54+
unsigned tstart = 0, tstop = 0;
5555

5656
struct SealerDescriptor
5757
{
@@ -538,7 +538,7 @@ class Farm: public FarmFace
538538
uint64_t m_nonce_scrambler;
539539
unsigned int m_nonce_segment_with = 40; // This is the exponent of the power 2^n which determines the width of each search segment assigned to each gpu
540540

541-
unsigned m_tstart, m_tstop;
541+
unsigned m_tstart = 0, m_tstop = 0;
542542

543543
wrap_nvml_handle *nvmlh = NULL;
544544
wrap_adl_handle *adlh = NULL;

‎libpoolprotocols/PoolClient.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ namespace dev
2929
virtual void disconnect() = 0;
3030

3131
virtual void submitHashrate(string const & rate) = 0;
32-
virtual void submitSolution(Solution solution) = 0;
32+
virtual void submitSolution(const Solution &solution) = 0;
3333
virtual bool isConnected() = 0;
3434
virtual bool isPendingState() = 0;
3535
virtual string ActiveEndPoint() = 0;

‎libpoolprotocols/getwork/EthGetworkClient.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ void EthGetworkClient::submitHashrate(string const & rate)
5656

5757
}
5858

59-
void EthGetworkClient::submitSolution(Solution solution)
59+
void EthGetworkClient::submitSolution(const Solution& solution)
6060
{
6161
// Immediately send found solution without wait for loop
6262
if (m_connected || m_justConnected) {

‎libpoolprotocols/getwork/EthGetworkClient.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class EthGetworkClient : public PoolClient, Worker
2525
string ActiveEndPoint() override { return ""; };
2626

2727
void submitHashrate(string const & rate) override;
28-
void submitSolution(Solution solution) override;
28+
void submitSolution(const Solution& solution) override;
2929

3030
private:
3131
void workLoop() override;
@@ -35,7 +35,7 @@ class EthGetworkClient : public PoolClient, Worker
3535

3636
bool m_justConnected = false;
3737
h256 m_client_id;
38-
JsonrpcGetwork *p_client;
38+
JsonrpcGetwork *p_client = nullptr;
3939
WorkPackage m_prevWorkPackage;
4040

4141
// Hashrate submission is optional

‎libpoolprotocols/stratum/EthStratumClient.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,8 @@ void EthStratumClient::disconnect()
173173
}
174174

175175
// Cancel any outstanding async operation
176-
m_socket->cancel();
176+
if (m_socket)
177+
m_socket->cancel();
177178

178179
m_io_service.post([&] {
179180
m_conntimer.cancel();
@@ -1041,7 +1042,7 @@ void EthStratumClient::submitHashrate(string const & rate) {
10411042

10421043
}
10431044

1044-
void EthStratumClient::submitSolution(Solution solution) {
1045+
void EthStratumClient::submitSolution(const Solution& solution) {
10451046

10461047
string nonceHex = toHex(solution.nonce);
10471048

‎libpoolprotocols/stratum/EthStratumClient.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class EthStratumClient : public PoolClient
3939
string ActiveEndPoint() override { return " [" + toString(m_endpoint) + "]"; };
4040

4141
void submitHashrate(string const & rate) override;
42-
void submitSolution(Solution solution) override;
42+
void submitSolution(const Solution &solution) override;
4343

4444
h256 currentHeaderHash() { return m_current.header; }
4545
bool current() { return static_cast<bool>(m_current); }
@@ -111,7 +111,7 @@ class EthStratumClient : public PoolClient
111111
h256 m_nextWorkBoundary = h256("0xffff000000000000000000000000000000000000000000000000000000000000");
112112

113113
h64 m_extraNonce;
114-
int m_extraNonceHexSize;
114+
int m_extraNonceHexSize = 0;
115115

116116
bool m_submit_hashrate;
117117
std::string m_submit_hashrate_id;

‎libpoolprotocols/testing/SimulateClient.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ void SimulateClient::submitHashrate(string const & rate)
4545
cnote << "On difficulty" << m_difficulty << "for" << sec.count() << "seconds";
4646
}
4747

48-
void SimulateClient::submitSolution(Solution solution)
48+
void SimulateClient::submitSolution(const Solution& solution)
4949
{
5050
m_uppDifficulty = true;
5151
cnote << "Difficulty:" << m_difficulty;

‎libpoolprotocols/testing/SimulateClient.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class SimulateClient : public PoolClient, Worker
2525
string ActiveEndPoint() override { return ""; };
2626

2727
void submitHashrate(string const & rate) override;
28-
void submitSolution(Solution solution) override;
28+
void submitSolution(const Solution& solution) override;
2929

3030
private:
3131
void workLoop() override;

0 commit comments

Comments
 (0)
This repository has been archived.