Merge pull request #324 from tekka007/nullTerminationFix2

Null termination issue, Fixes #322
This commit is contained in:
Henrik Ekblad
2016-01-05 13:08:04 +01:00
+4 -3
View File
@@ -203,10 +203,11 @@ MyMessage& MyMessage::set(const char* value) {
uint8_t length = value == NULL ? 0 : min(strlen(value), MAX_PAYLOAD); uint8_t length = value == NULL ? 0 : min(strlen(value), MAX_PAYLOAD);
miSetLength(length); miSetLength(length);
miSetPayloadType(P_STRING); miSetPayloadType(P_STRING);
if (length) if (length) {
strncpy(data, value, length); strncpy(data, value, length);
else }
data[0] ='\0'; // null terminate string
data[length] = 0;
return *this; return *this;
} }