8000 fixup! Make string concat, copy and move work on non-terminated strings · Cesar-Urteaga/ArduinoCore-API@d6fd84f · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

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)
0