fixed a bug in String::operator+ and String::operator+=
there was enough space allocated for both strings & the null-terminator
This commit is contained in:
		@@ -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
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user