From 524a99ccf69b4bf5c8188bc9e4d89f402c374cae Mon Sep 17 00:00:00 2001 From: Rob Hughes Date: Wed, 26 Jan 2022 09:30:57 +0000 Subject: IVGCVSW-6739 Fix logging bug where blank messages were being sent The ScopedRecord class sends its message to its sinks in its destructor. The StartNewRecord() method was creating a local ScopedRecord variable, returning a (move-initialised) copy of this, and then destroying this local variable (as the variable goes out of scope at the end of the function). That destruction was causing an empty log message to be sent to the sinks, which was not intended. This patch fixes this by making the move constructor of ScopedRecord disable the moved-from object, so that it does not send its message upon destruction. Change-Id: I435d96074698575ed3445fed2597c115b83701fd Signed-off-by: Rob Hughes --- include/armnn/Logging.hpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/include/armnn/Logging.hpp b/include/armnn/Logging.hpp index 9a60e07c63..d18072a22d 100644 --- a/include/armnn/Logging.hpp +++ b/include/armnn/Logging.hpp @@ -120,7 +120,15 @@ struct ScopedRecord ScopedRecord& operator=(const ScopedRecord&) = delete; ScopedRecord& operator=(ScopedRecord&&) = delete; - ScopedRecord(ScopedRecord&& other) = default; + ScopedRecord(ScopedRecord&& other) + : m_LogSinks(other.m_LogSinks) + , m_Os(std::move(other.m_Os)) + , m_Enabled(other.m_Enabled) + { + // Disable the moved-from ScopedRecord, to prevent it from sending its (now empty) message to + // its sinks. + other.m_Enabled = false; + } template ScopedRecord& operator<<(const Streamable& s) @@ -161,8 +169,7 @@ public: ScopedRecord StartNewRecord() { - ScopedRecord record(m_Sinks, Level, m_Enable); - return record; + return ScopedRecord(m_Sinks, Level, m_Enable); } void RemoveAllSinks() -- cgit v1.2.1