Make sure to terminate strings correctly.

This commit is contained in:
Henrik Ekblad
2014-07-13 00:02:20 +02:00
parent ef91d9b9cc
commit 767fedca5b
2 changed files with 3 additions and 2 deletions
+2 -1
View File
@@ -37,7 +37,8 @@ char* MyMessage::getString(char *buffer) const {
uint8_t payloadType = miGetPayloadType();
if (payloadType == P_STRING) {
strcpy(buffer, data);
strncpy(buffer, data, miGetLength());
buffer[miGetLength()] = '\0';
return buffer;
} else if (buffer != NULL) {
switch(payloadType) {
+1 -1
View File
@@ -269,7 +269,7 @@ boolean MySensor::process() {
RF24::read(&msg, len);
RF24::writeAckPayload(pipe,&pipe, 1 );
// Add termination, good for string messages.
// Add string termination, good if we later would want to print it.
msg.data[mGetLength(msg)] = '\0';
debug(PSTR("read: %d-%d-%d s=%d,c=%d,t=%d,pt=%d,l=%d:%s\n"),
msg.sender, msg.last, msg.destination, msg.sensor, mGetCommand(msg), msg.type, mGetPayloadType(msg), mGetLength(msg), msg.getString(convBuf));