From da227e48e9690b90f0487321e7985f4cd82c3c0d Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Wed, 23 Aug 2017 18:13:42 +0700 Subject: [PATCH] Fix String::Data copying/moving from self --- src/string.cc | 6 ++++++ 1 file changed, 6 insertions(+) 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(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())