mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-26 15:26:11 +01:00
Fix StringRef self-assignment after substring
Thanks to Alex Tkachenko for spotting it.
This commit is contained in:
parent
e680c4b9fb
commit
3bce8ba14b
@ -71,10 +71,12 @@ namespace Catch {
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto operator = ( StringRef const &other ) noexcept -> StringRef& {
|
auto operator = ( StringRef const &other ) noexcept -> StringRef& {
|
||||||
delete[] m_data;
|
if( this != &other ) {
|
||||||
m_data = nullptr;
|
delete[] m_data;
|
||||||
m_start = other.m_start;
|
m_data = nullptr;
|
||||||
m_size = other.m_size;
|
m_start = other.m_start;
|
||||||
|
m_size = other.m_size;
|
||||||
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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") {
|
||||||
|
Loading…
Reference in New Issue
Block a user