Skip to content

Commit 9a604e7

Browse files
fixup! Make string concat, copy and move work on non-terminated strings
1 parent b8c56da commit 9a604e7

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

Diff for: api/String.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ String & String::copy(const char *cstr, unsigned int length)
199199
}
200200
len = length;
201201
memcpy(buffer, cstr, length);
202+
buffer[len] = '\0';
202203
return *this;
203204
}
204205

@@ -220,6 +221,7 @@ void String::move(String &rhs)
220221
if (rhs && capacity >= rhs.len) {
221222
memcpy(buffer, rhs.buffer, rhs.len);
222223
len = rhs.len;
224+
buffer[len] = '\0';
223225
rhs.len = 0;
224226
return;
225227
} else {
@@ -292,6 +294,7 @@ unsigned char String::concat(const char *cstr, unsigned int length)
292294
if (!reserve(newlen)) return 0;
293295
memcpy(buffer + len, cstr, length);
294296
len = newlen;
297+
buffer[len] = '\0';
295298
return 1;
296299
}
297300

0 commit comments

Comments
 (0)