From 4db91a52eb4d342a0c4db89c40880830d8f78370 Mon Sep 17 00:00:00 2001 From: Alexey Rybalchenko Date: Fri, 26 Jun 2015 10:52:05 +0200 Subject: [PATCH] Fix Coverity issues --- fairmq/FairMQChannel.cxx | 260 +++++++++++++++++++++++----------- fairmq/FairMQStateMachine.cxx | 23 ++- 2 files changed, 197 insertions(+), 86 deletions(-) diff --git a/fairmq/FairMQChannel.cxx b/fairmq/FairMQChannel.cxx index 6562b4ec..29d82f31 100644 --- a/fairmq/FairMQChannel.cxx +++ b/fairmq/FairMQChannel.cxx @@ -14,6 +14,8 @@ #include +#include + #include "FairMQChannel.h" #include "FairMQLogger.h" @@ -49,139 +51,237 @@ FairMQChannel::FairMQChannel(const string& type, const string& method, const str std::string FairMQChannel::GetType() { - boost::unique_lock scoped_lock(channelMutex); - return fType; + try + { + boost::unique_lock scoped_lock(channelMutex); + return fType; + } + catch (boost::exception& e) + { + LOG(ERROR) << boost::diagnostic_information(e); + } } std::string FairMQChannel::GetMethod() { - boost::unique_lock scoped_lock(channelMutex); - return fMethod; + try + { + boost::unique_lock scoped_lock(channelMutex); + return fMethod; + } + catch (boost::exception& e) + { + LOG(ERROR) << boost::diagnostic_information(e); + } } std::string FairMQChannel::GetAddress() { - boost::unique_lock scoped_lock(channelMutex); - return fAddress; + try + { + boost::unique_lock scoped_lock(channelMutex); + return fAddress; + } + catch (boost::exception& e) + { + LOG(ERROR) << boost::diagnostic_information(e); + } } int FairMQChannel::GetSndBufSize() { - boost::unique_lock scoped_lock(channelMutex); - return fSndBufSize; + try + { + boost::unique_lock scoped_lock(channelMutex); + return fSndBufSize; + } + catch (boost::exception& e) + { + LOG(ERROR) << boost::diagnostic_information(e); + } } int FairMQChannel::GetRcvBufSize() { - boost::unique_lock scoped_lock(channelMutex); - return fRcvBufSize; + try + { + boost::unique_lock scoped_lock(channelMutex); + return fRcvBufSize; + } + catch (boost::exception& e) + { + LOG(ERROR) << boost::diagnostic_information(e); + } } int FairMQChannel::GetRateLogging() { - boost::unique_lock scoped_lock(channelMutex); - return fRateLogging; + try + { + boost::unique_lock scoped_lock(channelMutex); + return fRateLogging; + } + catch (boost::exception& e) + { + LOG(ERROR) << boost::diagnostic_information(e); + } } void FairMQChannel::UpdateType(const std::string& type) { - boost::unique_lock scoped_lock(channelMutex); - fType = type; + try + { + boost::unique_lock scoped_lock(channelMutex); + fType = type; + } + catch (boost::exception& e) + { + LOG(ERROR) << boost::diagnostic_information(e); + } } void FairMQChannel::UpdateMethod(const std::string& method) { - boost::unique_lock scoped_lock(channelMutex); - fMethod = method; + try + { + boost::unique_lock scoped_lock(channelMutex); + fMethod = method; + } + catch (boost::exception& e) + { + LOG(ERROR) << boost::diagnostic_information(e); + } } void FairMQChannel::UpdateAddress(const std::string& address) { - boost::unique_lock scoped_lock(channelMutex); - fAddress = address; + try + { + boost::unique_lock scoped_lock(channelMutex); + fAddress = address; + } + catch (boost::exception& e) + { + LOG(ERROR) << boost::diagnostic_information(e); + } } void FairMQChannel::UpdateSndBufSize(const int sndBufSize) { - boost::unique_lock scoped_lock(channelMutex); - fSndBufSize = sndBufSize; + try + { + boost::unique_lock scoped_lock(channelMutex); + fSndBufSize = sndBufSize; + } + catch (boost::exception& e) + { + LOG(ERROR) << boost::diagnostic_information(e); + } } void FairMQChannel::UpdateRcvBufSize(const int rcvBufSize) { - boost::unique_lock scoped_lock(channelMutex); - fRcvBufSize = rcvBufSize; + try + { + boost::unique_lock scoped_lock(channelMutex); + fRcvBufSize = rcvBufSize; + } + catch (boost::exception& e) + { + LOG(ERROR) << boost::diagnostic_information(e); + } } void FairMQChannel::UpdateRateLogging(const int rateLogging) { - boost::unique_lock scoped_lock(channelMutex); - fRateLogging = rateLogging; + try + { + boost::unique_lock scoped_lock(channelMutex); + fRateLogging = rateLogging; + } + catch (boost::exception& e) + { + LOG(ERROR) << boost::diagnostic_information(e); + } } bool FairMQChannel::IsValid() { - boost::unique_lock scoped_lock(channelMutex); - return fIsValid; + try + { + boost::unique_lock scoped_lock(channelMutex); + return fIsValid; + } + catch (boost::exception& e) + { + LOG(ERROR) << boost::diagnostic_information(e); + } } bool FairMQChannel::ValidateChannel() { - boost::unique_lock scoped_lock(channelMutex); - - stringstream ss; - ss << "Validating channel " << fChannelName << "... "; - - if (fIsValid) + try { - ss << "ALREADY VALID"; + boost::unique_lock scoped_lock(channelMutex); + + stringstream ss; + ss << "Validating channel " << fChannelName << "... "; + + if (fIsValid) + { + ss << "ALREADY VALID"; + LOG(DEBUG) << ss.str(); + return true; + } + + const string socketTypeNames[] = { "sub", "pub", "pull", "push", "req", "rep", "xsub", "xpub", "dealer", "router", "pair" }; + const set socketTypes(socketTypeNames, socketTypeNames + sizeof(socketTypeNames) / sizeof(string)); + if (socketTypes.find(fType) == socketTypes.end()) + { + ss << "INVALID"; + LOG(DEBUG) << ss.str(); + LOG(DEBUG) << "Invalid channel type: " << fType; + return false; + } + + const string socketMethodNames[] = { "bind", "connect" }; + const set socketMethods(socketMethodNames, socketMethodNames + sizeof(socketMethodNames) / sizeof(string)); + if (socketMethods.find(fMethod) == socketMethods.end()) + { + ss << "INVALID"; + LOG(DEBUG) << ss.str(); + LOG(DEBUG) << "Invalid channel method: " << fMethod; + return false; + } + + if (fAddress == "unspecified" || fAddress == "") + { + ss << "INVALID"; + LOG(DEBUG) << ss.str(); + LOG(DEBUG) << "invalid channel address: " << fAddress; + return false; + } + + if (fSndBufSize < 0) + { + ss << "INVALID"; + LOG(DEBUG) << ss.str(); + LOG(DEBUG) << "invalid channel send buffer size: " << fSndBufSize; + return false; + } + + if (fRcvBufSize < 0) + { + ss << "INVALID"; + LOG(DEBUG) << ss.str(); + LOG(DEBUG) << "invalid channel receive buffer size: " << fRcvBufSize; + return false; + } + + fIsValid = true; + ss << "VALID"; LOG(DEBUG) << ss.str(); return true; } - - const string socketTypeNames[] = { "sub", "pub", "pull", "push", "req", "rep", "xsub", "xpub", "dealer", "router", "pair" }; - const set socketTypes(socketTypeNames, socketTypeNames + sizeof(socketTypeNames) / sizeof(string)); - if (socketTypes.find(fType) == socketTypes.end()) + catch (boost::exception& e) { - ss << "INVALID"; - LOG(DEBUG) << ss.str(); - LOG(DEBUG) << "Invalid channel type: " << fType; - return false; + LOG(ERROR) << boost::diagnostic_information(e); } - - const string socketMethodNames[] = { "bind", "connect" }; - const set socketMethods(socketMethodNames, socketMethodNames + sizeof(socketMethodNames) / sizeof(string)); - if (socketMethods.find(fMethod) == socketMethods.end()) - { - ss << "INVALID"; - LOG(DEBUG) << ss.str(); - LOG(DEBUG) << "Invalid channel method: " << fMethod; - return false; - } - - if (fAddress == "unspecified" || fAddress == "") - { - ss << "INVALID"; - LOG(DEBUG) << ss.str(); - LOG(DEBUG) << "invalid channel address: " << fAddress; - return false; - } - - if (fSndBufSize < 0) - { - ss << "INVALID"; - LOG(DEBUG) << ss.str(); - LOG(DEBUG) << "invalid channel send buffer size: " << fSndBufSize; - return false; - } - - if (fRcvBufSize < 0) - { - ss << "INVALID"; - LOG(DEBUG) << ss.str(); - LOG(DEBUG) << "invalid channel receive buffer size: " << fRcvBufSize; - return false; - } - - fIsValid = true; - ss << "VALID"; - LOG(DEBUG) << ss.str(); - return true; } void FairMQChannel::ResetChannel() diff --git a/fairmq/FairMQStateMachine.cxx b/fairmq/FairMQStateMachine.cxx index e3af1756..906301c2 100644 --- a/fairmq/FairMQStateMachine.cxx +++ b/fairmq/FairMQStateMachine.cxx @@ -98,7 +98,11 @@ bool FairMQStateMachine::ChangeState(int event) return false; } } - catch (boost::exception &e) + catch (boost::thread_interrupted& e) + { + LOG(ERROR) << boost::diagnostic_information(e); + } + catch (boost::exception& e) { LOG(ERROR) << boost::diagnostic_information(e); } @@ -121,10 +125,17 @@ void FairMQStateMachine::WaitForEndOfState(int event) case RESET_TASK: case RESET_DEVICE: { - boost::unique_lock lock(fStateMutex); - while (!fStateFinished) + try { - fStateCondition.wait(lock); + boost::unique_lock lock(fStateMutex); + while (!fStateFinished) + { + fStateCondition.wait(lock); + } + } + catch (boost::exception& e) + { + LOG(ERROR) << boost::diagnostic_information(e); } break; } @@ -133,7 +144,7 @@ void FairMQStateMachine::WaitForEndOfState(int event) break; } } - catch (boost::exception &e) + catch (boost::thread_interrupted& e) { LOG(ERROR) << boost::diagnostic_information(e); } @@ -173,7 +184,7 @@ bool FairMQStateMachine::WaitForEndOfStateForMs(int event, int durationInMs) return false; } } - catch (boost::exception &e) + catch (boost::thread_interrupted &e) { LOG(ERROR) << boost::diagnostic_information(e); }