From 09bd8f26cb37b58310ce16bf7b8b6003b4244ed5 Mon Sep 17 00:00:00 2001 From: "Matthias P. Braendli" Date: Mon, 29 Oct 2018 16:06:11 +0100 Subject: Some fixes for issues seen with cppcheck --- src/ClockTAI.h | 2 +- src/InetAddress.cpp | 16 ---------------- src/InetAddress.h | 2 -- src/RemoteControl.cpp | 2 +- src/RemoteControl.h | 7 +++++-- 5 files changed, 7 insertions(+), 22 deletions(-) diff --git a/src/ClockTAI.h b/src/ClockTAI.h index ac4978c..e0dc439 100644 --- a/src/ClockTAI.h +++ b/src/ClockTAI.h @@ -78,7 +78,7 @@ class ClockTAI : public RemoteControllable { mutable std::mutex m_data_mutex; // The currently used TAI-UTC offset - int m_offset; + int m_offset = 0; int m_offset_valid = false; mutable std::stringstream m_bulletin; diff --git a/src/InetAddress.cpp b/src/InetAddress.cpp index d92e1b9..7660263 100644 --- a/src/InetAddress.cpp +++ b/src/InetAddress.cpp @@ -63,22 +63,6 @@ InetAddress::InetAddress(int port, const char* name) { } -/** - * Constructs a copy of inet - * @param inet The address to be copied - */ -InetAddress::InetAddress(const InetAddress &inet) { - TRACE_CLASS("InetAddress", "InetAddress(InetAddress)"); - memcpy(&addr, &inet.addr, sizeof(addr)); -} - - -/// Destructor -InetAddress::~InetAddress() { - TRACE_CLASS("InetAddress" ,"~InetAddress()"); -} - - /// Returns the raw IP address of this InetAddress object. sockaddr *InetAddress::getAddress() { TRACE_CLASS("InetAddress", "getAddress()"); diff --git a/src/InetAddress.h b/src/InetAddress.h index 0ccc70b..e246d4c 100644 --- a/src/InetAddress.h +++ b/src/InetAddress.h @@ -62,8 +62,6 @@ void setInetError(const char* description); class InetAddress { public: InetAddress(int port = 0, const char* name = NULL); - InetAddress(const InetAddress &addr); - ~InetAddress(); sockaddr *getAddress(); const char *getHostAddress(); diff --git a/src/RemoteControl.cpp b/src/RemoteControl.cpp index 517d99e..18c74b7 100644 --- a/src/RemoteControl.cpp +++ b/src/RemoteControl.cpp @@ -52,7 +52,7 @@ RemoteControllerTelnet::~RemoteControllerTelnet() } } -void RemoteControllerTelnet::restart() +void RemoteControllerTelnet::internal_restart() { if (m_restarter_thread.joinable()) { m_restarter_thread.join(); diff --git a/src/RemoteControl.h b/src/RemoteControl.h index b133a8f..7fc8e04 100644 --- a/src/RemoteControl.h +++ b/src/RemoteControl.h @@ -210,7 +210,9 @@ class RemoteControllerTelnet : public BaseRemoteController { m_fault(false), m_port(port) { - restart(); + // Don't call virtual functions from the ctor + // https://isocpp.org/wiki/faq/strange-inheritance#calling-virtuals-from-ctors + internal_restart(); } @@ -221,9 +223,10 @@ class RemoteControllerTelnet : public BaseRemoteController { virtual bool fault_detected() { return m_fault; } - virtual void restart(); + virtual void restart() { internal_restart(); } private: + void internal_restart(); void restart_thread(long); void process(long); -- cgit v1.2.3