From f21919419924ff1b25259c3fce3d5f914b775a5d Mon Sep 17 00:00:00 2001 From: Phil Nash Date: Tue, 22 Apr 2014 17:54:29 +0100 Subject: [PATCH] Replace some static strings with static char*s for leak detection friendliness (h/t #272) --- include/reporters/catch_reporter_console.hpp | 37 ++++++++------------ 1 file changed, 15 insertions(+), 22 deletions(-) diff --git a/include/reporters/catch_reporter_console.hpp b/include/reporters/catch_reporter_console.hpp index 71ca8905..62c3568f 100644 --- a/include/reporters/catch_reporter_console.hpp +++ b/include/reporters/catch_reporter_console.hpp @@ -256,7 +256,7 @@ namespace Catch { m_atLeastOneTestCasePrinted = true; } void lazyPrintRunInfo() { - stream << "\n" << getTildes() << "\n"; + stream << "\n" << getLineOfChars<'~'>() << "\n"; Colour colour( Colour::SecondaryText ); stream << currentTestRunInfo->name << " is a Catch v" << libraryVersion.majorVersion << "." @@ -292,19 +292,19 @@ namespace Catch { SourceLineInfo lineInfo = m_sectionStack.front().lineInfo; if( !lineInfo.empty() ){ - stream << getDashes() << "\n"; + stream << getLineOfChars<'-'>() << "\n"; Colour colourGuard( Colour::FileName ); stream << lineInfo << "\n"; } - stream << getDots() << "\n" << std::endl; + stream << getLineOfChars<'.'>() << "\n" << std::endl; } void printClosedHeader( std::string const& _name ) { printOpenHeader( _name ); - stream << getDots() << "\n"; + stream << getLineOfChars<'.'>() << "\n"; } void printOpenHeader( std::string const& _name ) { - stream << getDashes() << "\n"; + stream << getLineOfChars<'-'>() << "\n"; { Colour colourGuard( Colour::Headers ); printHeaderString( _name ); @@ -377,26 +377,19 @@ namespace Catch { } void printTotalsDivider() { - stream << getDoubleDashes() << "\n"; + stream << getLineOfChars<'='>() << "\n"; } void printSummaryDivider() { - stream << getDashes() << "\n"; + stream << getLineOfChars<'-'>() << "\n"; } - static std::string const& getDashes() { - static const std::string dashes( CATCH_CONFIG_CONSOLE_WIDTH-1, '-' ); - return dashes; - } - static std::string const& getDots() { - static const std::string dots( CATCH_CONFIG_CONSOLE_WIDTH-1, '.' ); - return dots; - } - static std::string const& getDoubleDashes() { - static const std::string doubleDashes( CATCH_CONFIG_CONSOLE_WIDTH-1, '=' ); - return doubleDashes; - } - static std::string const& getTildes() { - static const std::string dots( CATCH_CONFIG_CONSOLE_WIDTH-1, '~' ); - return dots; + template + static char const* getLineOfChars() { + static char line[CATCH_CONFIG_CONSOLE_WIDTH] = {0}; + if( !*line ) { + memset( line, C, CATCH_CONFIG_CONSOLE_WIDTH-1 ); + line[CATCH_CONFIG_CONSOLE_WIDTH-1] = 0; + } + return line; } private: