From 9c895ec3e042205df243e175a06967a975d8f645 Mon Sep 17 00:00:00 2001 From: Pawel Kubik Date: Mon, 7 Sep 2015 11:17:45 +0200 Subject: [PATCH] cppcheck fixes [Feature] Small code fixes based on cppcheck [Cause] Minimizing possible runtime errors [Solution] Fix the code using cppcheck suggestions, suppress false-positives [Verification] Compile, run cppcheck Change-Id: I94fab8e50879f78f3ccb503fd18606e9cbfabfb5 --- cli/cli-exception.hpp | 4 +-- client/exception.hpp | 10 +++--- client/vasum-client-impl.cpp | 1 - common/api/ipc-method-result-builder.hpp | 2 +- common/base-exception.hpp | 2 +- common/lxc/exception.hpp | 4 +-- common/utils/exception.hpp | 4 +-- libs/dbus/exception.hpp | 10 +++--- libs/ipc/exception.hpp | 16 +++++----- libs/ipc/internals/finish-request.hpp | 2 +- libs/ipc/internals/method-request.hpp | 6 ++-- libs/ipc/internals/processor.cpp | 26 ++++++++-------- libs/ipc/internals/processor.hpp | 46 ++++++++++++++-------------- libs/ipc/internals/remove-peer-request.hpp | 2 +- libs/ipc/internals/result-builder.hpp | 10 ++---- libs/ipc/internals/send-result-request.hpp | 4 +-- libs/ipc/internals/signal-request.hpp | 6 ++-- libs/ipc/method-result.cpp | 6 ++-- libs/ipc/method-result.hpp | 6 ++-- libs/ipc/service.hpp | 8 ++--- libs/lxcpp/exception.hpp | 22 ++++++------- server/exception.hpp | 14 ++++----- server/zones-manager.cpp | 4 +-- tests/cppcheck/cppcheck.sh | 4 ++- tests/cppcheck/cppcheck.suppress | 23 ++++++++++++-- tests/unit_tests/ipc/ut-ipc.cpp | 2 +- tests/unit_tests/server/ut-zones-manager.cpp | 11 +++---- tests/unit_tests/utils/ut-worker.cpp | 2 +- zone-daemon/exception.hpp | 2 +- 29 files changed, 135 insertions(+), 124 deletions(-) diff --git a/cli/cli-exception.hpp b/cli/cli-exception.hpp index 982f52d..f0d5e0f 100644 --- a/cli/cli-exception.hpp +++ b/cli/cli-exception.hpp @@ -38,12 +38,12 @@ namespace cli { */ struct CliException: public VasumException { - CliException(const std::string& error) : VasumException(error) {} + explicit CliException(const std::string& error) : VasumException(error) {} }; struct IOException: public CliException { - IOException(const std::string& error) : CliException(error) {} + explicit IOException(const std::string& error) : CliException(error) {} }; } // namespace cli diff --git a/client/exception.hpp b/client/exception.hpp index d4be66b..98ebf81 100644 --- a/client/exception.hpp +++ b/client/exception.hpp @@ -37,27 +37,27 @@ namespace vasum { */ struct ClientException: public VasumException { - ClientException(const std::string& error) : VasumException(error) {} + explicit ClientException(const std::string& error) : VasumException(error) {} }; struct IOException: public ClientException { - IOException(const std::string& error) : ClientException(error) {} + explicit IOException(const std::string& error) : ClientException(error) {} }; struct OperationFailedException: public ClientException { - OperationFailedException(const std::string& error) : ClientException(error) {} + explicit OperationFailedException(const std::string& error) : ClientException(error) {} }; struct InvalidArgumentException: public ClientException { - InvalidArgumentException(const std::string& error) : ClientException(error) {} + explicit InvalidArgumentException(const std::string& error) : ClientException(error) {} }; struct InvalidResponseException: public ClientException { - InvalidResponseException(const std::string& error) : ClientException(error) {} + explicit InvalidResponseException(const std::string& error) : ClientException(error) {} }; } diff --git a/client/vasum-client-impl.cpp b/client/vasum-client-impl.cpp index e3aca1d..41cc919 100644 --- a/client/vasum-client-impl.cpp +++ b/client/vasum-client-impl.cpp @@ -899,4 +899,3 @@ VsmStatus Client::vsm_clean_up_zones_root() noexcept std::make_shared()); }); } - diff --git a/common/api/ipc-method-result-builder.hpp b/common/api/ipc-method-result-builder.hpp index e9554d0..cad5d8a 100644 --- a/common/api/ipc-method-result-builder.hpp +++ b/common/api/ipc-method-result-builder.hpp @@ -40,7 +40,7 @@ const std::string IPC_CONNECTION_PREFIX = "ipc://"; class IPCMethodResultBuilder: public MethodResultBuilder { public: - IPCMethodResultBuilder(const ipc::MethodResult::Pointer& methodResult); + explicit IPCMethodResultBuilder(const ipc::MethodResult::Pointer& methodResult); ~IPCMethodResultBuilder() {} private: diff --git a/common/base-exception.hpp b/common/base-exception.hpp index 645fa41..05e1fd6 100644 --- a/common/base-exception.hpp +++ b/common/base-exception.hpp @@ -38,7 +38,7 @@ namespace vasum { */ struct VasumException: public std::runtime_error { - VasumException(const std::string& error) : std::runtime_error(error) {} + explicit VasumException(const std::string& error) : std::runtime_error(error) {} }; } // namespace vasum diff --git a/common/lxc/exception.hpp b/common/lxc/exception.hpp index 379fe43..40c7d5f 100644 --- a/common/lxc/exception.hpp +++ b/common/lxc/exception.hpp @@ -37,12 +37,12 @@ namespace vasum { */ struct LxcException: public VasumException { - LxcException(const std::string& error) : VasumException(error) {} + explicit LxcException(const std::string& error) : VasumException(error) {} }; struct KeyNotFoundException: public LxcException { - KeyNotFoundException(const std::string& error) : LxcException(error) {} + explicit KeyNotFoundException(const std::string& error) : LxcException(error) {} }; } // namespace vasum diff --git a/common/utils/exception.hpp b/common/utils/exception.hpp index fda0554..232b090 100644 --- a/common/utils/exception.hpp +++ b/common/utils/exception.hpp @@ -36,12 +36,12 @@ namespace utils { */ struct UtilsException: public std::runtime_error { - UtilsException(const std::string& error) : std::runtime_error(error) {} + explicit UtilsException(const std::string& error) : std::runtime_error(error) {} }; struct ProvisionExistsException: public UtilsException { - ProvisionExistsException(const std::string& error) : UtilsException(error) {} + explicit ProvisionExistsException(const std::string& error) : UtilsException(error) {} }; /** diff --git a/libs/dbus/exception.hpp b/libs/dbus/exception.hpp index a09bdbc..b38877c 100644 --- a/libs/dbus/exception.hpp +++ b/libs/dbus/exception.hpp @@ -34,7 +34,7 @@ namespace dbus { */ struct DbusException: public std::runtime_error { - DbusException(const std::string& error = "") : std::runtime_error(error) {} + explicit DbusException(const std::string& error = "") : std::runtime_error(error) {} }; /** @@ -42,7 +42,7 @@ struct DbusException: public std::runtime_error { */ struct DbusIOException: public DbusException { - DbusIOException(const std::string& error = "") : DbusException(error) {} + explicit DbusIOException(const std::string& error = "") : DbusException(error) {} }; /** @@ -50,7 +50,7 @@ struct DbusIOException: public DbusException { */ struct DbusOperationException: public DbusException { - DbusOperationException(const std::string& error = "") : DbusException(error) {} + explicit DbusOperationException(const std::string& error = "") : DbusException(error) {} }; /** @@ -58,7 +58,7 @@ struct DbusOperationException: public DbusException { */ struct DbusCustomException: public DbusException { - DbusCustomException(const std::string& error = "") : DbusException(error) {} + explicit DbusCustomException(const std::string& error = "") : DbusException(error) {} }; /** @@ -66,7 +66,7 @@ struct DbusCustomException: public DbusException { */ struct DbusInvalidArgumentException: public DbusException { - DbusInvalidArgumentException(const std::string& error = "") : DbusException(error) {} + explicit DbusInvalidArgumentException(const std::string& error = "") : DbusException(error) {} }; } // namespace dbus diff --git a/libs/ipc/exception.hpp b/libs/ipc/exception.hpp index 140619c..3fe7a5b 100644 --- a/libs/ipc/exception.hpp +++ b/libs/ipc/exception.hpp @@ -36,7 +36,7 @@ namespace ipc { * @defgroup IPCException IPCException */ struct IPCException: public std::runtime_error { - IPCException(const std::string& message) + explicit IPCException(const std::string& message) : std::runtime_error(message) {} }; @@ -45,7 +45,7 @@ struct IPCException: public std::runtime_error { * @ingroup IPCException */ struct IPCParsingException: public IPCException { - IPCParsingException(const std::string& message = "Exception during reading/parsing data from the socket") + explicit IPCParsingException(const std::string& message = "Exception during reading/parsing data from the socket") : IPCException(message) {} }; @@ -54,7 +54,7 @@ struct IPCParsingException: public IPCException { * @ingroup IPCException */ struct IPCSerializationException: public IPCException { - IPCSerializationException(const std::string& message = "Exception during writing/serializing data to the socket") + explicit IPCSerializationException(const std::string& message = "Exception during writing/serializing data to the socket") : IPCException(message) {} }; @@ -63,7 +63,7 @@ struct IPCSerializationException: public IPCException { * @ingroup IPCException */ struct IPCPeerDisconnectedException: public IPCException { - IPCPeerDisconnectedException(const std::string& message = "No such peer. Might got disconnected.") + explicit IPCPeerDisconnectedException(const std::string& message = "No such peer. Might got disconnected.") : IPCException(message) {} }; @@ -72,7 +72,7 @@ struct IPCPeerDisconnectedException: public IPCException { * @ingroup IPCException */ struct IPCNaughtyPeerException: public IPCException { - IPCNaughtyPeerException(const std::string& message = "Peer performed a forbidden action.") + explicit IPCNaughtyPeerException(const std::string& message = "Peer performed a forbidden action.") : IPCException(message) {} }; @@ -81,7 +81,7 @@ struct IPCNaughtyPeerException: public IPCException { * @ingroup IPCException */ struct IPCRemovedPeerException: public IPCException { - IPCRemovedPeerException(const std::string& message = "Removing peer") + explicit IPCRemovedPeerException(const std::string& message = "Removing peer") : IPCException(message) {} }; @@ -90,7 +90,7 @@ struct IPCRemovedPeerException: public IPCException { * @ingroup IPCException */ struct IPCClosingException: public IPCException { - IPCClosingException(const std::string& message = "Closing IPC") + explicit IPCClosingException(const std::string& message = "Closing IPC") : IPCException(message) {} }; @@ -99,7 +99,7 @@ struct IPCClosingException: public IPCException { * @ingroup IPCException */ struct IPCTimeoutException: public IPCException { - IPCTimeoutException(const std::string& message) + explicit IPCTimeoutException(const std::string& message) : IPCException(message) {} }; diff --git a/libs/ipc/internals/finish-request.hpp b/libs/ipc/internals/finish-request.hpp index 5a948bd..934c135 100644 --- a/libs/ipc/internals/finish-request.hpp +++ b/libs/ipc/internals/finish-request.hpp @@ -43,4 +43,4 @@ public: } // namespace ipc -#endif // COMMON_IPC_INTERNALS_FINISH_REQUEST_HPP \ No newline at end of file +#endif // COMMON_IPC_INTERNALS_FINISH_REQUEST_HPP diff --git a/libs/ipc/internals/method-request.hpp b/libs/ipc/internals/method-request.hpp index 663cbde..53d9d44 100644 --- a/libs/ipc/internals/method-request.hpp +++ b/libs/ipc/internals/method-request.hpp @@ -41,7 +41,7 @@ public: template static std::shared_ptr create(const MethodID methodID, - const PeerID peerID, + const PeerID& peerID, const std::shared_ptr& data, const typename ResultHandler::type& process); @@ -54,7 +54,7 @@ public: ResultBuilderHandler process; private: - MethodRequest(const MethodID methodID, const PeerID peerID) + MethodRequest(const MethodID methodID, const PeerID& peerID) : methodID(methodID), peerID(peerID), messageID(getNextMessageID()) @@ -64,7 +64,7 @@ private: template std::shared_ptr MethodRequest::create(const MethodID methodID, - const PeerID peerID, + const PeerID& peerID, const std::shared_ptr& data, const typename ResultHandler::type& process) { diff --git a/libs/ipc/internals/processor.cpp b/libs/ipc/internals/processor.cpp index fdbcbe8..164d735 100644 --- a/libs/ipc/internals/processor.cpp +++ b/libs/ipc/internals/processor.cpp @@ -92,7 +92,7 @@ Processor::Peers::iterator Processor::getPeerInfoIterator(const FileDescriptor f }); } -Processor::Peers::iterator Processor::getPeerInfoIterator(const PeerID peerID) +Processor::Peers::iterator Processor::getPeerInfoIterator(const PeerID & peerID) { return std::find_if(mPeerInfo.begin(), mPeerInfo.end(), [peerID](const PeerInfo & peerInfo) { return peerID == peerInfo.peerID; @@ -162,16 +162,16 @@ FileDescriptor Processor::getEventFD() } void Processor::sendResult(const MethodID methodID, - const PeerID peerID, - const MessageID messageID, + const PeerID& peerID, + const MessageID& messageID, const std::shared_ptr& data) { auto requestPtr = std::make_shared(methodID, peerID, messageID, data); mRequestQueue.pushFront(Event::SEND_RESULT, requestPtr); } -void Processor::sendError(const PeerID peerID, - const MessageID messageID, +void Processor::sendError(const PeerID& peerID, + const MessageID& messageID, const int errorCode, const std::string& message) { @@ -180,8 +180,8 @@ void Processor::sendError(const PeerID peerID, } void Processor::sendVoid(const MethodID methodID, - const PeerID peerID, - const MessageID messageID) + const PeerID& peerID, + const MessageID& messageID) { auto data = std::make_shared(); auto requestPtr = std::make_shared(methodID, peerID, messageID, data); @@ -208,7 +208,7 @@ PeerID Processor::addPeer(const std::shared_ptr& socketPtr) return requestPtr->peerID; } -void Processor::removePeerSyncInternal(const PeerID peerID, Lock& lock) +void Processor::removePeerSyncInternal(const PeerID& peerID, Lock& lock) { LOGS(mLogPrefix + "Processor removePeer peerID: " << peerID); @@ -329,7 +329,7 @@ bool Processor::handleInput(const FileDescriptor fd) } } -void Processor::onNewSignals(const PeerID peerID, std::shared_ptr& data) +void Processor::onNewSignals(const PeerID& peerID, std::shared_ptr& data) { LOGS(mLogPrefix + "Processor onNewSignals peerID: " << peerID); @@ -338,7 +338,7 @@ void Processor::onNewSignals(const PeerID peerID, std::shared_ptr& data) +void Processor::onErrorSignal(const PeerID&, std::shared_ptr& data) { LOGS(mLogPrefix + "Processor onErrorSignal messageID: " << data->messageID); @@ -351,7 +351,7 @@ void Processor::onErrorSignal(const PeerID, std::shared_ptr signalCallbacks) { LOGS(mLogPrefix + "Processor onRemoteSignal; methodID: " << methodID << " messageID: " << messageID); @@ -422,7 +422,7 @@ bool Processor::onRemoteSignal(Peers::iterator& peerIt, bool Processor::onRemoteMethod(Peers::iterator& peerIt, const MethodID methodID, - const MessageID messageID, + const MessageID& messageID, std::shared_ptr methodCallbacks) { LOGS(mLogPrefix + "Processor onRemoteMethod; methodID: " << methodID << " messageID: " << messageID); diff --git a/libs/ipc/internals/processor.hpp b/libs/ipc/internals/processor.hpp index e383a57..91edfc1 100644 --- a/libs/ipc/internals/processor.hpp +++ b/libs/ipc/internals/processor.hpp @@ -217,8 +217,8 @@ public: * @param data data to send */ void sendResult(const MethodID methodID, - const PeerID peerID, - const MessageID messageID, + const PeerID& peerID, + const MessageID& messageID, const std::shared_ptr& data); /** @@ -229,8 +229,8 @@ public: * @param errorCode code of the error * @param message description of the error */ - void sendError(const PeerID peerID, - const MessageID messageID, + void sendError(const PeerID& peerID, + const MessageID& messageID, const int errorCode, const std::string& message); @@ -242,8 +242,8 @@ public: * @param messageID id of the message to which it replies */ void sendVoid(const MethodID methodID, - const PeerID peerID, - const MessageID messageID); + const PeerID& peerID, + const MessageID& messageID); /** * Removes the callback associated with specific method id. @@ -267,7 +267,7 @@ public: */ template std::shared_ptr callSync(const MethodID methodID, - const PeerID peerID, + const PeerID& peerID, const std::shared_ptr& data, unsigned int timeoutMS = 5000); @@ -283,7 +283,7 @@ public: */ template MessageID callAsync(const MethodID methodID, - const PeerID peerID, + const PeerID& peerID, const std::shared_ptr& data, const typename ResultHandler::type& process); @@ -352,7 +352,7 @@ private: struct RegisterSignalsProtocolMessage { RegisterSignalsProtocolMessage() = default; - RegisterSignalsProtocolMessage(const std::vector& ids) + explicit RegisterSignalsProtocolMessage(const std::vector& ids) : ids(ids) {} std::vector ids; @@ -365,7 +365,7 @@ private: struct ErrorProtocolMessage { ErrorProtocolMessage() = default; - ErrorProtocolMessage(const MessageID messageID, const int code, const std::string& message) + ErrorProtocolMessage(const MessageID& messageID, const int code, const std::string& message) : messageID(messageID), code(code), message(message) {} MessageID messageID; @@ -461,7 +461,7 @@ private: template MessageID callAsyncInternal(const MethodID methodID, - const PeerID peerID, + const PeerID& peerID, const std::shared_ptr& data, const typename ResultHandler::type& process); @@ -475,7 +475,7 @@ private: template void signalInternal(const MethodID methodID, - const PeerID peerID, + const PeerID& peerID, const std::shared_ptr& data); // Request handlers @@ -487,28 +487,28 @@ private: bool onFinishRequest(FinishRequest& request); bool onReturnValue(Peers::iterator& peerIt, - const MessageID messageID); + const MessageID& messageID); bool onRemoteMethod(Peers::iterator& peerIt, const MethodID methodID, - const MessageID messageID, + const MessageID& messageID, std::shared_ptr methodCallbacks); bool onRemoteSignal(Peers::iterator& peerIt, const MethodID methodID, - const MessageID messageID, + const MessageID& messageID, std::shared_ptr signalCallbacks); void removePeerInternal(Peers::iterator peerIt, const std::exception_ptr& exceptionPtr); - void removePeerSyncInternal(const PeerID peerID, Lock& lock); + void removePeerSyncInternal(const PeerID& peerID, Lock& lock); - void onNewSignals(const PeerID peerID, + void onNewSignals(const PeerID& peerID, std::shared_ptr& data); - void onErrorSignal(const PeerID peerID, + void onErrorSignal(const PeerID& peerID, std::shared_ptr& data); Peers::iterator getPeerInfoIterator(const FileDescriptor fd); - Peers::iterator getPeerInfoIterator(const PeerID peerID); + Peers::iterator getPeerInfoIterator(const PeerID& peerID); }; @@ -616,7 +616,7 @@ void Processor::setSignalHandler(const MethodID methodID, template MessageID Processor::callAsync(const MethodID methodID, - const PeerID peerID, + const PeerID& peerID, const std::shared_ptr& data, const typename ResultHandler::type& process) { @@ -626,7 +626,7 @@ MessageID Processor::callAsync(const MethodID methodID, template MessageID Processor::callAsyncInternal(const MethodID methodID, - const PeerID peerID, + const PeerID& peerID, const std::shared_ptr& data, const typename ResultHandler::type& process) { @@ -638,7 +638,7 @@ MessageID Processor::callAsyncInternal(const MethodID methodID, template std::shared_ptr Processor::callSync(const MethodID methodID, - const PeerID peerID, + const PeerID& peerID, const std::shared_ptr& data, unsigned int timeoutMS) { @@ -692,7 +692,7 @@ std::shared_ptr Processor::callSync(const MethodID methodID, template void Processor::signalInternal(const MethodID methodID, - const PeerID peerID, + const PeerID& peerID, const std::shared_ptr& data) { auto requestPtr = SignalRequest::create(methodID, peerID, data); diff --git a/libs/ipc/internals/remove-peer-request.hpp b/libs/ipc/internals/remove-peer-request.hpp index c9f7ec7..e124227 100644 --- a/libs/ipc/internals/remove-peer-request.hpp +++ b/libs/ipc/internals/remove-peer-request.hpp @@ -37,7 +37,7 @@ public: RemovePeerRequest(const RemovePeerRequest&) = delete; RemovePeerRequest& operator=(const RemovePeerRequest&) = delete; - RemovePeerRequest(const PeerID peerID, + RemovePeerRequest(const PeerID& peerID, const std::shared_ptr& conditionPtr) : peerID(peerID), conditionPtr(conditionPtr) diff --git a/libs/ipc/internals/result-builder.hpp b/libs/ipc/internals/result-builder.hpp index 97134e3..b9c9471 100644 --- a/libs/ipc/internals/result-builder.hpp +++ b/libs/ipc/internals/result-builder.hpp @@ -39,12 +39,12 @@ public: mExceptionPtr(nullptr) {} - ResultBuilder(const std::exception_ptr& exceptionPtr) + explicit ResultBuilder(const std::exception_ptr& exceptionPtr) : mData(nullptr), mExceptionPtr(exceptionPtr) {} - ResultBuilder(const std::shared_ptr& data) + explicit ResultBuilder(const std::shared_ptr& data) : mData(data), mExceptionPtr(nullptr) @@ -68,9 +68,3 @@ typedef std::function ResultBuilderHandler; } // namespace ipc #endif // COMMON_IPC_RESULT_BUILDER_HPP - - - - - - diff --git a/libs/ipc/internals/send-result-request.hpp b/libs/ipc/internals/send-result-request.hpp index a6ed2b4..de512c0 100644 --- a/libs/ipc/internals/send-result-request.hpp +++ b/libs/ipc/internals/send-result-request.hpp @@ -36,8 +36,8 @@ public: SendResultRequest& operator=(const SendResultRequest&) = delete; SendResultRequest(const MethodID methodID, - const PeerID peerID, - const MessageID messageID, + const PeerID& peerID, + const MessageID& messageID, const std::shared_ptr& data) : methodID(methodID), peerID(peerID), diff --git a/libs/ipc/internals/signal-request.hpp b/libs/ipc/internals/signal-request.hpp index 904d3f3..aa597c0 100644 --- a/libs/ipc/internals/signal-request.hpp +++ b/libs/ipc/internals/signal-request.hpp @@ -38,7 +38,7 @@ public: template static std::shared_ptr create(const MethodID methodID, - const PeerID peerID, + const PeerID& peerID, const std::shared_ptr& data); MethodID methodID; @@ -48,7 +48,7 @@ public: SerializeCallback serialize; private: - SignalRequest(const MethodID methodID, const PeerID peerID) + SignalRequest(const MethodID methodID, const PeerID& peerID) : methodID(methodID), peerID(peerID), messageID(getNextMessageID()) @@ -58,7 +58,7 @@ private: template std::shared_ptr SignalRequest::create(const MethodID methodID, - const PeerID peerID, + const PeerID& peerID, const std::shared_ptr& data) { std::shared_ptr request(new SignalRequest(methodID, peerID)); diff --git a/libs/ipc/method-result.cpp b/libs/ipc/method-result.cpp index 97eb450..f110689 100644 --- a/libs/ipc/method-result.cpp +++ b/libs/ipc/method-result.cpp @@ -31,8 +31,8 @@ namespace ipc { MethodResult::MethodResult(Processor& processor, const MethodID methodID, - const MessageID messageID, - const PeerID peerID) + const MessageID& messageID, + const PeerID& peerID) : mProcessor(processor), mMethodID(methodID), mPeerID(peerID), @@ -54,7 +54,7 @@ void MethodResult::setError(const int code, const std::string& message) mProcessor.sendError(mPeerID, mMessageID, code, message); } -PeerID MethodResult::getPeerID() +PeerID MethodResult::getPeerID() const { return mPeerID; } diff --git a/libs/ipc/method-result.hpp b/libs/ipc/method-result.hpp index c1729f7..c6fce37 100644 --- a/libs/ipc/method-result.hpp +++ b/libs/ipc/method-result.hpp @@ -43,8 +43,8 @@ public: MethodResult(Processor& processor, const MethodID methodID, - const MessageID messageID, - const PeerID peerID); + const MessageID& messageID, + const PeerID& peerID); template @@ -55,7 +55,7 @@ public: void setVoid(); void setError(const int code, const std::string& message); - PeerID getPeerID(); + PeerID getPeerID() const; private: Processor& mProcessor; diff --git a/libs/ipc/service.hpp b/libs/ipc/service.hpp index a5f7c86..6d953dd 100644 --- a/libs/ipc/service.hpp +++ b/libs/ipc/service.hpp @@ -191,7 +191,7 @@ public: */ template std::shared_ptr callSync(const MethodID methodID, - const PeerID peerID, + const PeerID& peerID, const std::shared_ptr& data, unsigned int timeoutMS = 5000); @@ -208,7 +208,7 @@ public: */ template void callAsync(const MethodID methodID, - const PeerID peerID, + const PeerID& peerID, const std::shared_ptr& data, const typename ResultHandler::type& resultCallback); @@ -251,7 +251,7 @@ void Service::setSignalHandler(const MethodID methodID, template std::shared_ptr Service::callSync(const MethodID methodID, - const PeerID peerID, + const PeerID& peerID, const std::shared_ptr& data, unsigned int timeoutMS) { @@ -263,7 +263,7 @@ std::shared_ptr Service::callSync(const MethodID methodID, template void Service::callAsync(const MethodID methodID, - const PeerID peerID, + const PeerID& peerID, const std::shared_ptr& data, const typename ResultHandler::type& resultCallback) { diff --git a/libs/lxcpp/exception.hpp b/libs/lxcpp/exception.hpp index af81779..7764282 100644 --- a/libs/lxcpp/exception.hpp +++ b/libs/lxcpp/exception.hpp @@ -32,57 +32,57 @@ namespace lxcpp { * Base class for exceptions in lxcpp */ struct Exception: public std::runtime_error { - Exception(const std::string& message) + explicit Exception(const std::string& message) : std::runtime_error(message) {} }; struct NotImplementedException: public Exception { - NotImplementedException(const std::string& message = "Functionality not yet implemented") + explicit NotImplementedException(const std::string& message = "Functionality not yet implemented") : Exception(message) {} }; struct ProcessSetupException: public Exception { - ProcessSetupException(const std::string& message = "Error while setting up a process") + explicit ProcessSetupException(const std::string& message = "Error while setting up a process") : Exception(message) {} }; struct FileSystemSetupException: public Exception { - FileSystemSetupException(const std::string& message = "Error during a file system operation") + explicit FileSystemSetupException(const std::string& message = "Error during a file system operation") : Exception(message) {} }; struct EnvironmentSetupException: public Exception { - EnvironmentSetupException(const std::string& message = "Error during handling environment variables") + explicit EnvironmentSetupException(const std::string& message = "Error during handling environment variables") : Exception(message) {} }; struct CredentialSetupException: public Exception { - CredentialSetupException(const std::string& message = "Error during handling environment variables") + explicit CredentialSetupException(const std::string& message = "Error during handling environment variables") : Exception(message) {} }; struct CapabilitySetupException: public Exception { - CapabilitySetupException(const std::string& message = "Error during a capability operation") + explicit CapabilitySetupException(const std::string& message = "Error during a capability operation") : Exception(message) {} }; struct BadArgument: public Exception { - BadArgument(const std::string& message = "Bad argument passed") + explicit BadArgument(const std::string& message = "Bad argument passed") : Exception(message) {} }; struct NoSuchValue: public Exception { - NoSuchValue(const std::string& message = "Value not found") + explicit NoSuchValue(const std::string& message = "Value not found") : Exception(message) {} }; struct NetworkException : public Exception { - NetworkException (const std::string& message = "Error during setting up a network") + explicit NetworkException (const std::string& message = "Error during setting up a network") : Exception(message) {} }; struct ConfigureException: public Exception { - ConfigureException(const std::string& message = "Error while configuring a container") + explicit ConfigureException(const std::string& message = "Error while configuring a container") : Exception(message) {} }; diff --git a/server/exception.hpp b/server/exception.hpp index e1b3be4..e72df76 100644 --- a/server/exception.hpp +++ b/server/exception.hpp @@ -37,7 +37,7 @@ namespace vasum { */ struct ServerException: public VasumException { - ServerException(const std::string& error) : VasumException(error) {} + explicit ServerException(const std::string& error) : VasumException(error) {} }; /** @@ -46,7 +46,7 @@ struct ServerException: public VasumException { */ struct ZoneOperationException: public ServerException { - ZoneOperationException(const std::string& error) : ServerException(error) {} + explicit ZoneOperationException(const std::string& error) : ServerException(error) {} }; /** @@ -54,7 +54,7 @@ struct ZoneOperationException: public ServerException { */ struct InvalidZoneIdException : public ServerException { - InvalidZoneIdException(const std::string& error) : ServerException(error) {} + explicit InvalidZoneIdException(const std::string& error) : ServerException(error) {} }; /** @@ -62,7 +62,7 @@ struct InvalidZoneIdException : public ServerException { */ struct ZoneConnectionException: public ServerException { - ZoneConnectionException(const std::string& error) : ServerException(error) {} + explicit ZoneConnectionException(const std::string& error) : ServerException(error) {} }; /** @@ -70,7 +70,7 @@ struct ZoneConnectionException: public ServerException { */ struct HostConnectionException: public ServerException { - HostConnectionException(const std::string& error) : ServerException(error) {} + explicit HostConnectionException(const std::string& error) : ServerException(error) {} }; /** @@ -79,12 +79,12 @@ struct HostConnectionException: public ServerException { */ struct InputMonitorException: public ServerException { - InputMonitorException(const std::string& error) : ServerException(error) {} + explicit InputMonitorException(const std::string& error) : ServerException(error) {} }; struct TimeoutException: public InputMonitorException { - TimeoutException(const std::string& error) : InputMonitorException (error) {} + explicit TimeoutException(const std::string& error) : InputMonitorException (error) {} }; } diff --git a/server/zones-manager.cpp b/server/zones-manager.cpp index 55e63f5..baf3ed1 100644 --- a/server/zones-manager.cpp +++ b/server/zones-manager.cpp @@ -1266,7 +1266,7 @@ void ZonesManager::createZone(const std::string& id, } catch (std::runtime_error& e) { LOGE("Generate config failed: " << e.what()); utils::launchAsRoot(std::bind(removeAllWrapper, zonePathStr)); - throw e; + throw; } LOGT("Creating new zone"); @@ -1275,7 +1275,7 @@ void ZonesManager::createZone(const std::string& id, } catch (std::runtime_error& e) { LOGE("Creating new zone failed: " << e.what()); utils::launchAsRoot(std::bind(removeAllWrapper, zonePathStr)); - throw e; + throw; } mDynamicConfig.zoneIds.push_back(id); diff --git a/tests/cppcheck/cppcheck.sh b/tests/cppcheck/cppcheck.sh index b8bb637..bbe96b5 100755 --- a/tests/cppcheck/cppcheck.sh +++ b/tests/cppcheck/cppcheck.sh @@ -11,5 +11,7 @@ OPT+=" -I common" OPT+=" -I libs" OPT+=" -I client" OPT+=" -I server" +OPT+=" -I tests/unit_tests" +OPT+=" -I tests/unit_tests/socket_test_service" OPT+=" -U__NR_capset" -cppcheck ${OPT} --template=gcc ./ 1>/dev/null +cppcheck ${OPT} --template=gcc $@ ./ 1>/dev/null diff --git a/tests/cppcheck/cppcheck.suppress b/tests/cppcheck/cppcheck.suppress index d3b098f..8d7380b 100644 --- a/tests/cppcheck/cppcheck.suppress +++ b/tests/cppcheck/cppcheck.suppress @@ -1,7 +1,26 @@ // public API functions (or write tests to use them all) unusedFunction:wrapper/wrapper-compatibility.cpp unusedFunction:wrapper/wrapper.cpp +unusedFunction:libs/config/kvstore.cpp +unusedFunction:libs/ipc/internals/processor.cpp +unusedFunction:server/zones-manager.cpp +unusedFunction:libs/lxcpp/container-impl.cpp +unusedFunction:libs/lxcpp/filesystem.cpp +unusedFunction:libs/lxcpp/network.cpp +unusedFunction:libs/lxcpp/network-config.cpp +unusedFunction:client/vasum-client.cpp +unusedFunction:common/netlink/netlink-message.cpp +unusedFunction:common/utils/fd-utils.cpp +unusedFunction:server/zone.cpp -// lambda not recognized to catch exception (v1.68) -exceptThrowInNoexecptFunction:client/vasum-client-impl.cpp +// lambda not recognized to catch exception (v1.69) +throwInNoexceptFunction:client/vasum-client-impl.cpp +// complains that all constructors with 1 argument should be explicit +noExplicitConstructor + +// required for C abstraction +unusedStructMember:common/utils/initctl.cpp + +// functions called by external utilities +unusedFunction:tests/unit_tests/ut.cpp diff --git a/tests/unit_tests/ipc/ut-ipc.cpp b/tests/unit_tests/ipc/ut-ipc.cpp index 853faa2..5ba540e 100644 --- a/tests/unit_tests/ipc/ut-ipc.cpp +++ b/tests/unit_tests/ipc/ut-ipc.cpp @@ -237,7 +237,7 @@ void testEcho(Client& c, const MethodID methodID) BOOST_CHECK_EQUAL(recvData->intVal, sentData->intVal); } -void testEcho(Service& s, const MethodID methodID, const PeerID peerID) +void testEcho(Service& s, const MethodID methodID, const PeerID& peerID) { std::shared_ptr sentData(new SendData(56)); std::shared_ptr recvData = s.callSync(methodID, peerID, sentData, TIMEOUT); diff --git a/tests/unit_tests/server/ut-zones-manager.cpp b/tests/unit_tests/server/ut-zones-manager.cpp index 819da53..6d6a71d 100644 --- a/tests/unit_tests/server/ut-zones-manager.cpp +++ b/tests/unit_tests/server/ut-zones-manager.cpp @@ -163,7 +163,7 @@ public: void signalSubscribe(const DbusConnection::SignalCallback& callback) { - mClient->signalSubscribe(callback, isHost() ? api::dbus::BUS_NAME : api::dbus::BUS_NAME); + mClient->signalSubscribe(callback, api::dbus::BUS_NAME); } void callSwitchToDefault() @@ -225,12 +225,9 @@ public: interface.c_str(), method.c_str(), parameters); - GVariantPtr result = mClient->callMethod(isHost() ? api::dbus::BUS_NAME : - api::dbus::BUS_NAME, - isHost() ? api::dbus::OBJECT_PATH : - api::dbus::OBJECT_PATH, - isHost() ? api::dbus::INTERFACE : - api::dbus::INTERFACE, + GVariantPtr result = mClient->callMethod(api::dbus::BUS_NAME, + api::dbus::OBJECT_PATH, + api::dbus::INTERFACE, api::dbus::METHOD_PROXY_CALL, packedParameters, "(v)"); diff --git a/tests/unit_tests/utils/ut-worker.cpp b/tests/unit_tests/utils/ut-worker.cpp index 52c14fd..b05aef0 100644 --- a/tests/unit_tests/utils/ut-worker.cpp +++ b/tests/unit_tests/utils/ut-worker.cpp @@ -166,7 +166,7 @@ BOOST_AUTO_TEST_CASE(NoCopy) Task(Task&& r) : count(r.count) {} Task& operator=(const Task&) = delete; Task& operator=(Task&&) = delete; - void operator() () {} + void operator() () const {} }; diff --git a/zone-daemon/exception.hpp b/zone-daemon/exception.hpp index 5fcf54d..9889e62 100644 --- a/zone-daemon/exception.hpp +++ b/zone-daemon/exception.hpp @@ -37,7 +37,7 @@ namespace zone_daemon { */ struct ZoneDaemonException: public VasumException { - ZoneDaemonException(const std::string& error) : VasumException(error) {} + explicit ZoneDaemonException(const std::string& error) : VasumException(error) {} }; -- 2.7.4