From e1f555bc057f77edac26e58c81455e83cb4442d6 Mon Sep 17 00:00:00 2001 From: Alexey Rybalchenko Date: Mon, 8 Oct 2018 12:42:35 +0200 Subject: [PATCH] Fix issues found by Codacy --- fairmq/FairMQChannel.cxx | 7 +++++-- fairmq/FairMQDevice.cxx | 4 +--- fairmq/FairMQPoller.h | 4 ++-- fairmq/FairMQStateMachine.cxx | 2 +- fairmq/FairMQStateMachine.h | 2 +- fairmq/nanomsg/FairMQPollerNN.cxx | 7 +++---- fairmq/nanomsg/FairMQPollerNN.h | 4 ++-- fairmq/nanomsg/FairMQSocketNN.cxx | 7 ++----- fairmq/ofi/Poller.cxx | 3 +-- fairmq/plugins/Control.cxx | 2 +- fairmq/plugins/Control.h | 2 +- fairmq/plugins/DDS/DDS.cxx | 2 +- fairmq/plugins/DDS/DDS.h | 2 +- fairmq/plugins/DDS/runDDSCommandUI.cxx | 2 +- fairmq/shmem/FairMQPollerSHM.cxx | 7 +++---- fairmq/shmem/FairMQPollerSHM.h | 4 ++-- fairmq/shmem/FairMQSocketSHM.cxx | 18 +++++++--------- fairmq/shmem/FairMQTransportFactorySHM.cxx | 4 +--- fairmq/shmem/Monitor.cxx | 2 +- fairmq/shmem/runMonitor.cxx | 2 +- fairmq/tools/Process.cxx | 2 +- fairmq/tools/Process.h | 2 +- fairmq/zeromq/FairMQPollerZMQ.cxx | 7 +++---- fairmq/zeromq/FairMQPollerZMQ.h | 4 ++-- fairmq/zeromq/FairMQSocketZMQ.cxx | 24 ++++++++-------------- 25 files changed, 53 insertions(+), 73 deletions(-) diff --git a/fairmq/FairMQChannel.cxx b/fairmq/FairMQChannel.cxx index 681170cf..66cc94c1 100644 --- a/fairmq/FairMQChannel.cxx +++ b/fairmq/FairMQChannel.cxx @@ -104,19 +104,22 @@ FairMQChannel::FairMQChannel(const FairMQChannel& chan) FairMQChannel& FairMQChannel::operator=(const FairMQChannel& chan) { + fSocket = nullptr; fType = chan.fType; fMethod = chan.fMethod; fAddress = chan.fAddress; + fTransportType = chan.fTransportType; fSndBufSize = chan.fSndBufSize; fRcvBufSize = chan.fRcvBufSize; fSndKernelSize = chan.fSndKernelSize; fRcvKernelSize = chan.fRcvKernelSize; fRateLogging = chan.fRateLogging; - fSocket = nullptr; fName = chan.fName; fIsValid = false; - fTransportType = chan.fTransportType; fTransportFactory = nullptr; + fMultipart = chan.fMultipart; + fModified = chan.fModified; + fReset = false; return *this; } diff --git a/fairmq/FairMQDevice.cxx b/fairmq/FairMQDevice.cxx index 7f0763e2..2154305e 100644 --- a/fairmq/FairMQDevice.cxx +++ b/fairmq/FairMQDevice.cxx @@ -816,8 +816,6 @@ void FairMQDevice::LogSocketRates() chrono::time_point t0; chrono::time_point t1; - unsigned long long msSinceLastLog; - vector filteredSockets; vector filteredChannelNames; vector logIntervals; @@ -879,7 +877,7 @@ void FairMQDevice::LogSocketRates() { t1 = chrono::high_resolution_clock::now(); - msSinceLastLog = chrono::duration_cast(t1 - t0).count(); + unsigned long long msSinceLastLog = chrono::duration_cast(t1 - t0).count(); i = 0; diff --git a/fairmq/FairMQPoller.h b/fairmq/FairMQPoller.h index 1494f068..ec2d7c8e 100644 --- a/fairmq/FairMQPoller.h +++ b/fairmq/FairMQPoller.h @@ -18,8 +18,8 @@ class FairMQPoller virtual void Poll(const int timeout) = 0; virtual bool CheckInput(const int index) = 0; virtual bool CheckOutput(const int index) = 0; - virtual bool CheckInput(const std::string channelKey, const int index) = 0; - virtual bool CheckOutput(const std::string channelKey, const int index) = 0; + virtual bool CheckInput(const std::string& channelKey, const int index) = 0; + virtual bool CheckOutput(const std::string& channelKey, const int index) = 0; virtual ~FairMQPoller() {}; }; diff --git a/fairmq/FairMQStateMachine.cxx b/fairmq/FairMQStateMachine.cxx index 72d41064..3cefbd48 100644 --- a/fairmq/FairMQStateMachine.cxx +++ b/fairmq/FairMQStateMachine.cxx @@ -644,7 +644,7 @@ bool FairMQStateMachine::CheckCurrentState(int state) const { return state == static_pointer_cast(fFsm)->fState; } -bool FairMQStateMachine::CheckCurrentState(string state) const +bool FairMQStateMachine::CheckCurrentState(const string& state) const { return state == GetCurrentStateName(); } diff --git a/fairmq/FairMQStateMachine.h b/fairmq/FairMQStateMachine.h index 2c149e43..e406abd1 100644 --- a/fairmq/FairMQStateMachine.h +++ b/fairmq/FairMQStateMachine.h @@ -82,7 +82,7 @@ class FairMQStateMachine static std::string GetStateName(const State); int GetCurrentState() const; bool CheckCurrentState(int state) const; - bool CheckCurrentState(std::string state) const; + bool CheckCurrentState(const std::string& state) const; // actions to be overwritten by derived classes virtual void InitWrapper() {} diff --git a/fairmq/nanomsg/FairMQPollerNN.cxx b/fairmq/nanomsg/FairMQPollerNN.cxx index 09f7e1d5..5fa3f10f 100644 --- a/fairmq/nanomsg/FairMQPollerNN.cxx +++ b/fairmq/nanomsg/FairMQPollerNN.cxx @@ -68,10 +68,9 @@ FairMQPollerNN::FairMQPollerNN(const unordered_map , fNumItems(0) , fOffsetMap() { - int offset = 0; - try { + int offset = 0; // calculate offsets and the total size of the poll item set for (string channel : channelList) { @@ -184,7 +183,7 @@ bool FairMQPollerNN::CheckOutput(const int index) return false; } -bool FairMQPollerNN::CheckInput(const string channelKey, const int index) +bool FairMQPollerNN::CheckInput(const string& channelKey, const int index) { try { @@ -203,7 +202,7 @@ bool FairMQPollerNN::CheckInput(const string channelKey, const int index) } } -bool FairMQPollerNN::CheckOutput(const string channelKey, const int index) +bool FairMQPollerNN::CheckOutput(const string& channelKey, const int index) { try { diff --git a/fairmq/nanomsg/FairMQPollerNN.h b/fairmq/nanomsg/FairMQPollerNN.h index 7df9b2b7..7d5ec5eb 100644 --- a/fairmq/nanomsg/FairMQPollerNN.h +++ b/fairmq/nanomsg/FairMQPollerNN.h @@ -44,8 +44,8 @@ class FairMQPollerNN : public FairMQPoller virtual void Poll(const int timeout); virtual bool CheckInput(const int index); virtual bool CheckOutput(const int index); - virtual bool CheckInput(const std::string channelKey, const int index); - virtual bool CheckOutput(const std::string channelKey, const int index); + virtual bool CheckInput(const std::string& channelKey, const int index); + virtual bool CheckOutput(const std::string& channelKey, const int index); virtual ~FairMQPollerNN(); diff --git a/fairmq/nanomsg/FairMQSocketNN.cxx b/fairmq/nanomsg/FairMQSocketNN.cxx index 3cdf4bd4..3a5a92c1 100644 --- a/fairmq/nanomsg/FairMQSocketNN.cxx +++ b/fairmq/nanomsg/FairMQSocketNN.cxx @@ -197,7 +197,6 @@ int FairMQSocketNN::SendImpl(FairMQMessagePtr& msg, const int flags, const int t int FairMQSocketNN::ReceiveImpl(FairMQMessagePtr& msg, const int flags, const int timeout) { - int nbytes = -1; int elapsed = 0; FairMQMessageNN* msgPtr = static_cast(msg.get()); @@ -205,7 +204,7 @@ int FairMQSocketNN::ReceiveImpl(FairMQMessagePtr& msg, const int flags, const in while (true) { void* ptr = nullptr; - nbytes = nn_recv(fSocket, &ptr, NN_MSG, flags); + int nbytes = nn_recv(fSocket, &ptr, NN_MSG, flags); if (nbytes >= 0) { fBytesRx += nbytes; @@ -279,11 +278,9 @@ int64_t FairMQSocketNN::SendImpl(vector& msgVec, const int fla } } - int64_t nbytes = -1; - while (true) { - nbytes = nn_send(fSocket, sbuf.data(), sbuf.size(), flags); + int64_t nbytes = nn_send(fSocket, sbuf.data(), sbuf.size(), flags); if (nbytes >= 0) { fBytesTx += nbytes; diff --git a/fairmq/ofi/Poller.cxx b/fairmq/ofi/Poller.cxx index 9af0f96b..52be52bf 100644 --- a/fairmq/ofi/Poller.cxx +++ b/fairmq/ofi/Poller.cxx @@ -59,9 +59,8 @@ Poller::Poller(const vector& channels) Poller::Poller(const unordered_map>& channelsMap, const vector& channelList) { - int offset = 0; - try { + int offset = 0; // calculate offsets and the total size of the poll item set for (string channel : channelList) { fOffsetMap[channel] = offset; diff --git a/fairmq/plugins/Control.cxx b/fairmq/plugins/Control.cxx index d4fc9988..578657b1 100644 --- a/fairmq/plugins/Control.cxx +++ b/fairmq/plugins/Control.cxx @@ -33,7 +33,7 @@ namespace mq namespace plugins { -Control::Control(const string name, const Plugin::Version version, const string maintainer, const string homepage, PluginServices* pluginServices) +Control::Control(const string& name, const Plugin::Version version, const string& maintainer, const string& homepage, PluginServices* pluginServices) : Plugin(name, version, maintainer, homepage, pluginServices) , fControllerThread() , fSignalHandlerThread() diff --git a/fairmq/plugins/Control.h b/fairmq/plugins/Control.h index 027fa263..802deaac 100644 --- a/fairmq/plugins/Control.h +++ b/fairmq/plugins/Control.h @@ -29,7 +29,7 @@ namespace plugins class Control : public Plugin { public: - Control(const std::string name, const Plugin::Version version, const std::string maintainer, const std::string homepage, PluginServices* pluginServices); + Control(const std::string& name, const Plugin::Version version, const std::string& maintainer, const std::string& homepage, PluginServices* pluginServices); ~Control(); diff --git a/fairmq/plugins/DDS/DDS.cxx b/fairmq/plugins/DDS/DDS.cxx index 86b8aae3..1df9842d 100644 --- a/fairmq/plugins/DDS/DDS.cxx +++ b/fairmq/plugins/DDS/DDS.cxx @@ -31,7 +31,7 @@ namespace mq namespace plugins { -DDS::DDS(const string name, const Plugin::Version version, const string maintainer, const string homepage, PluginServices* pluginServices) +DDS::DDS(const string& name, const Plugin::Version version, const string& maintainer, const string& homepage, PluginServices* pluginServices) : Plugin(name, version, maintainer, homepage, pluginServices) , fService() , fDDSCustomCmd(fService) diff --git a/fairmq/plugins/DDS/DDS.h b/fairmq/plugins/DDS/DDS.h index 5efb6a30..ee3232bc 100644 --- a/fairmq/plugins/DDS/DDS.h +++ b/fairmq/plugins/DDS/DDS.h @@ -61,7 +61,7 @@ struct IofN class DDS : public Plugin { public: - DDS(const std::string name, const Plugin::Version version, const std::string maintainer, const std::string homepage, PluginServices* pluginServices); + DDS(const std::string& name, const Plugin::Version version, const std::string& maintainer, const std::string& homepage, PluginServices* pluginServices); ~DDS(); diff --git a/fairmq/plugins/DDS/runDDSCommandUI.cxx b/fairmq/plugins/DDS/runDDSCommandUI.cxx index 62396f75..04d9baa1 100644 --- a/fairmq/plugins/DDS/runDDSCommandUI.cxx +++ b/fairmq/plugins/DDS/runDDSCommandUI.cxx @@ -33,7 +33,7 @@ int main(int argc, char* argv[]) { try { string sessionID; - char command; + char command = ' '; string topologyPath; bpo::options_description options("fairmq-dds-command-ui options"); diff --git a/fairmq/shmem/FairMQPollerSHM.cxx b/fairmq/shmem/FairMQPollerSHM.cxx index 90edec89..c7e852dc 100644 --- a/fairmq/shmem/FairMQPollerSHM.cxx +++ b/fairmq/shmem/FairMQPollerSHM.cxx @@ -68,10 +68,9 @@ FairMQPollerSHM::FairMQPollerSHM(const unordered_map>& msgVec) { int FairMQSocketSHM::SendImpl(FairMQMessagePtr& msg, const int flags, const int timeout) { - int nbytes = -1; int elapsed = 0; while (true && !fInterrupted) { - nbytes = zmq_msg_send(static_cast(msg.get())->GetMessage(), fSocket, flags); + int nbytes = zmq_msg_send(static_cast(msg.get())->GetMessage(), fSocket, flags); if (nbytes == 0) { return nbytes; @@ -177,13 +176,12 @@ int FairMQSocketSHM::SendImpl(FairMQMessagePtr& msg, const int flags, const int int FairMQSocketSHM::ReceiveImpl(FairMQMessagePtr& msg, const int flags, const int timeout) { - int nbytes = -1; int elapsed = 0; zmq_msg_t* msgPtr = static_cast(msg.get())->GetMessage(); while (true) { - nbytes = zmq_msg_recv(msgPtr, fSocket, flags); + int nbytes = zmq_msg_recv(msgPtr, fSocket, flags); if (nbytes == 0) { ++fMessagesRx; @@ -249,7 +247,6 @@ int FairMQSocketSHM::ReceiveImpl(FairMQMessagePtr& msg, const int flags, const i int64_t FairMQSocketSHM::SendImpl(vector& msgVec, const int flags, const int timeout) { const unsigned int vecSize = msgVec.size(); - int64_t totalSize = 0; int elapsed = 0; if (vecSize == 1) { @@ -263,7 +260,7 @@ int64_t FairMQSocketSHM::SendImpl(vector& msgVec, const int fl // prepare the message with shm metas MetaHeader* metas = static_cast(zmq_msg_data(&zmqMsg)); - for (auto &msg : msgVec) + for (auto& msg : msgVec) { zmq_msg_t* metaMsg = static_cast(msg.get())->GetMessage(); memcpy(metas++, zmq_msg_data(metaMsg), sizeof(MetaHeader)); @@ -271,9 +268,8 @@ int64_t FairMQSocketSHM::SendImpl(vector& msgVec, const int fl while (!fInterrupted) { - int nbytes = -1; - nbytes = zmq_msg_send(&zmqMsg, fSocket, flags); - + int64_t totalSize = 0; + int nbytes = zmq_msg_send(&zmqMsg, fSocket, flags); if (nbytes == 0) { zmq_msg_close(&zmqMsg); @@ -283,7 +279,7 @@ int64_t FairMQSocketSHM::SendImpl(vector& msgVec, const int fl { assert(nbytes == (vecSize * sizeof(MetaHeader))); // all or nothing - for (auto &msg : msgVec) + for (auto& msg : msgVec) { FairMQMessageSHM* shmMsg = static_cast(msg.get()); shmMsg->fQueued = true; @@ -338,7 +334,6 @@ int64_t FairMQSocketSHM::SendImpl(vector& msgVec, const int fl int64_t FairMQSocketSHM::ReceiveImpl(vector& msgVec, const int flags, const int timeout) { - int64_t totalSize = 0; int elapsed = 0; zmq_msg_t zmqMsg; @@ -346,6 +341,7 @@ int64_t FairMQSocketSHM::ReceiveImpl(vector& msgVec, const int while (!fInterrupted) { + int64_t totalSize = 0; int nbytes = zmq_msg_recv(&zmqMsg, fSocket, flags); if (nbytes == 0) { diff --git a/fairmq/shmem/FairMQTransportFactorySHM.cxx b/fairmq/shmem/FairMQTransportFactorySHM.cxx index 03ff2ec6..89697d07 100644 --- a/fairmq/shmem/FairMQTransportFactorySHM.cxx +++ b/fairmq/shmem/FairMQTransportFactorySHM.cxx @@ -145,8 +145,6 @@ FairMQTransportFactorySHM::FairMQTransportFactorySHM(const string& id, const Fai void FairMQTransportFactorySHM::StartMonitor() { - int numTries = 0; - auto env = boost::this_process::environment(); vector ownPath = boost::this_process::path(); @@ -161,7 +159,7 @@ void FairMQTransportFactorySHM::StartMonitor() if (!p.empty()) { boost::process::spawn(p, "-x", "-s", fSessionName, "-d", "-t", "2000", env); - + int numTries = 0; do { MonitorStatus* monitorStatus = fManager->ManagementSegment().find(bipc::unique_instance).first; diff --git a/fairmq/shmem/Monitor.cxx b/fairmq/shmem/Monitor.cxx index 61c62062..792a97d5 100644 --- a/fairmq/shmem/Monitor.cxx +++ b/fairmq/shmem/Monitor.cxx @@ -245,11 +245,11 @@ void Monitor::Interactive() void Monitor::CheckSegment() { - static uint64_t counter = 0; char c = '#'; if (fInteractive) { + static uint64_t counter = 0; int mod = counter++ % 5; switch (mod) { diff --git a/fairmq/shmem/runMonitor.cxx b/fairmq/shmem/runMonitor.cxx index 52863971..f06a070c 100644 --- a/fairmq/shmem/runMonitor.cxx +++ b/fairmq/shmem/runMonitor.cxx @@ -71,7 +71,7 @@ int main(int argc, char** argv) bool cleanup = false; bool selfDestruct = false; bool interactive = false; - unsigned int timeoutInMS; + unsigned int timeoutInMS = 5000; bool runAsDaemon = false; bool cleanOnExit = false; diff --git a/fairmq/tools/Process.cxx b/fairmq/tools/Process.cxx index ac19aab8..a8ec0293 100644 --- a/fairmq/tools/Process.cxx +++ b/fairmq/tools/Process.cxx @@ -30,7 +30,7 @@ namespace tools * @param[in] log_prefix How to prefix each captured output line with * @return Captured stdout output and exit code */ -execute_result execute(string cmd, string prefix) +execute_result execute(const string& cmd, const string& prefix) { execute_result result; stringstream out; diff --git a/fairmq/tools/Process.h b/fairmq/tools/Process.h index ddd867f4..3b5691fb 100644 --- a/fairmq/tools/Process.h +++ b/fairmq/tools/Process.h @@ -35,7 +35,7 @@ struct execute_result * @param[in] log_prefix How to prefix each captured output line with * @return Captured stdout output and exit code */ -execute_result execute(std::string cmd, std::string prefix = ""); +execute_result execute(const std::string& cmd, const std::string& prefix = ""); } /* namespace tools */ } /* namespace mq */ diff --git a/fairmq/zeromq/FairMQPollerZMQ.cxx b/fairmq/zeromq/FairMQPollerZMQ.cxx index c34b9ca6..235ec35f 100644 --- a/fairmq/zeromq/FairMQPollerZMQ.cxx +++ b/fairmq/zeromq/FairMQPollerZMQ.cxx @@ -69,10 +69,9 @@ FairMQPollerZMQ::FairMQPollerZMQ(const unordered_map>& msgVec) { int FairMQSocketZMQ::SendImpl(FairMQMessagePtr& msg, const int flags, const int timeout) { - int nbytes = -1; int elapsed = 0; static_cast(msg.get())->ApplyUsedSize(); while (true) { - nbytes = zmq_msg_send(static_cast(msg.get())->GetMessage(), fSocket, flags); + int nbytes = zmq_msg_send(static_cast(msg.get())->GetMessage(), fSocket, flags); if (nbytes >= 0) { fBytesTx += nbytes; @@ -212,25 +211,21 @@ int FairMQSocketZMQ::ReceiveImpl(FairMQMessagePtr& msg, const int flags, const i int64_t FairMQSocketZMQ::SendImpl(vector& msgVec, const int flags, const int timeout) { const unsigned int vecSize = msgVec.size(); - int elapsed = 0; // Sending vector typicaly handles more then one part if (vecSize > 1) { - int64_t totalSize = 0; - int nbytes = -1; - bool repeat = false; - + int elapsed = 0; while (true) { - totalSize = 0; - repeat = false; + int64_t totalSize = 0; + bool repeat = false; for (unsigned int i = 0; i < vecSize; ++i) { static_cast(msgVec[i].get())->ApplyUsedSize(); - nbytes = zmq_msg_send(static_cast(msgVec[i].get())->GetMessage(), + int nbytes = zmq_msg_send(static_cast(msgVec[i].get())->GetMessage(), fSocket, (i < vecSize - 1) ? ZMQ_SNDMORE|flags : flags); if (nbytes >= 0) @@ -294,16 +289,13 @@ int64_t FairMQSocketZMQ::SendImpl(vector& msgVec, const int fl int64_t FairMQSocketZMQ::ReceiveImpl(vector& msgVec, const int flags, const int timeout) { - int64_t totalSize = 0; - int64_t more = 0; - bool repeat = false; int elapsed = 0; while (true) { - totalSize = 0; - more = 0; - repeat = false; + int64_t totalSize = 0; + int64_t more = 0; + bool repeat = false; do {