Skip to content

Commit 0ebaced

Browse files
committed
Merge pull request arduino#324 from tekka007/nullTerminationFix2
Null termination issue, Fixes arduino#322
2 parents 7ee3950 + 39407e4 commit 0ebaced

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

libraries/MySensors/core/MyMessage.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -203,10 +203,11 @@ MyMessage& MyMessage::set(const char* value) {
203203
uint8_t length = value == NULL ? 0 : min(strlen(value), MAX_PAYLOAD);
204204
miSetLength(length);
205205
miSetPayloadType(P_STRING);
206-
if (length)
206+
if (length) {
207207
strncpy(data, value, length);
208-
else
209-
data[0] ='\0';
208+
}
209+
// null terminate string
210+
data[length] = 0;
210211
return *this;
211212
}
212213

0 commit comments

Comments
 (0)