Skip to content

Commit d6fd84f

Browse files
fixup! Make string concat, copy and move work on non-terminated strings
1 parent 0d83f1a commit d6fd84f

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

api/String.cpp

Lines changed: 3 additions & 0 deletions
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy