diff --git a/String.cpp b/String.cpp index 3ec4b01..c460e43 100644 --- a/String.cpp +++ b/String.cpp @@ -51,7 +51,7 @@ String::String(String&& other) noexcept : String() // init via default ctor so String String::operator+(const String& rhs) const { - auto size = this->size() + rhs.size() - 1; // minus one null-terminator, we need only one + auto size = this->size() + rhs.size() + 1; // plus a null-terminator auto data = new char[size]; // make some space std::strcpy(data, this->c_str()); // copy data of this String ret; @@ -62,7 +62,7 @@ String String::operator+(const String& rhs) const String& String::operator+=(const String& other) { - auto size = this->size() + other.size() - 1; // minus one null-terminator, we need only one + auto size = this->size() + other.size() + 1; // plus a null-terminator auto data = new char[size]; std::strcpy(data, this->c_str()); // copy our data std::strcat(data, other.c_str()); // append data of the other string