Fix StringRef self-assignment after substring

Thanks to Alex Tkachenko for spotting it.
This commit is contained in:
Phil Nash 2019-05-18 17:54:06 +01:00
parent e680c4b9fb
commit 3bce8ba14b
2 changed files with 11 additions and 4 deletions

View File

@ -71,10 +71,12 @@ namespace Catch {
} }
auto operator = ( StringRef const &other ) noexcept -> StringRef& { auto operator = ( StringRef const &other ) noexcept -> StringRef& {
if( this != &other ) {
delete[] m_data; delete[] m_data;
m_data = nullptr; m_data = nullptr;
m_start = other.m_start; m_start = other.m_start;
m_size = other.m_size; m_size = other.m_size;
}
return *this; return *this;
} }

View File

@ -92,6 +92,11 @@ TEST_CASE( "StringRef", "[Strings][StringRef]" ) {
REQUIRE( isOwned( ss ) ); REQUIRE( isOwned( ss ) );
REQUIRE( ss.currentData() != s.currentData() ); // different pointer value REQUIRE( ss.currentData() != s.currentData() ); // different pointer value
SECTION( "Self-assignment after substring" ) {
ss = ss;
REQUIRE(isOwned(ss) == true);
}
} }
SECTION( "non-zero-based substring") { SECTION( "non-zero-based substring") {