summaryrefslogtreecommitdiff
path: root/src/string.cc
diff options
context:
space:
mode:
authorMaxime Coste <mawww@kakoune.org>2017-08-23 18:13:42 +0700
committerMaxime Coste <mawww@kakoune.org>2017-08-23 18:13:42 +0700
commitda227e48e9690b90f0487321e7985f4cd82c3c0d (patch)
tree22be3d553ce4b004f906ec47933d5818e1a84dec /src/string.cc
parentf7bed9eb183def6ad1e96df96c13fd22551fbf42 (diff)
Fix String::Data copying/moving from self
Diffstat (limited to 'src/string.cc')
-rw-r--r--src/string.cc6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/string.cc b/src/string.cc
index 1ab56481..f14abddb 100644
--- a/src/string.cc
+++ b/src/string.cc
@@ -43,6 +43,9 @@ String::Data::Data(Data&& other) noexcept
String::Data& String::Data::operator=(const Data& other)
{
+ if (&other == this)
+ return *this;
+
const size_t new_size = other.size();
reserve<false>(new_size);
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
{
+ if (&other == this)
+ return *this;
+
release();
if (other.is_long())