Fix String::Data copying/moving from self
This commit is contained in:
parent
f7bed9eb18
commit
da227e48e9
|
@ -43,6 +43,9 @@ String::Data::Data(Data&& other) noexcept
|
||||||
|
|
||||||
String::Data& String::Data::operator=(const Data& other)
|
String::Data& String::Data::operator=(const Data& other)
|
||||||
{
|
{
|
||||||
|
if (&other == this)
|
||||||
|
return *this;
|
||||||
|
|
||||||
const size_t new_size = other.size();
|
const size_t new_size = other.size();
|
||||||
reserve<false>(new_size);
|
reserve<false>(new_size);
|
||||||
memcpy(data(), other.data(), new_size+1);
|
memcpy(data(), other.data(), new_size+1);
|
||||||
|
@ -53,6 +56,9 @@ String::Data& String::Data::operator=(const Data& other)
|
||||||
|
|
||||||
String::Data& String::Data::operator=(Data&& other) noexcept
|
String::Data& String::Data::operator=(Data&& other) noexcept
|
||||||
{
|
{
|
||||||
|
if (&other == this)
|
||||||
|
return *this;
|
||||||
|
|
||||||
release();
|
release();
|
||||||
|
|
||||||
if (other.is_long())
|
if (other.is_long())
|
||||||
|
|
Loading…
Reference in New Issue
Block a user