fix check for NULL buffer in getString()

This commit is contained in:
Marcelo Aquino
2015-05-04 16:19:37 -03:00
parent b0737a7311
commit 1acee7b988
+5 -6
View File
@@ -61,12 +61,11 @@ char* MyMessage::getStream(char *buffer) const {
char* MyMessage::getString(char *buffer) const { char* MyMessage::getString(char *buffer) const {
uint8_t payloadType = miGetPayloadType(); uint8_t payloadType = miGetPayloadType();
if (payloadType == P_STRING) { if (buffer != NULL) {
strncpy(buffer, data, miGetLength()); if (payloadType == P_STRING) {
buffer[miGetLength()] = 0; strncpy(buffer, data, miGetLength());
return buffer; buffer[miGetLength()] = 0;
} else if (buffer != NULL) { } else if (payloadType == P_BYTE) {
if (payloadType == P_BYTE) {
itoa(bValue, buffer, 10); itoa(bValue, buffer, 10);
} else if (payloadType == P_INT16) { } else if (payloadType == P_INT16) {
itoa(iValue, buffer, 10); itoa(iValue, buffer, 10);