Add a check when publishing data to be able to publish a message without data without crashing.

Signed-off-by: Marius Vikhammer <marius.vikhammer@espressif.com>

Merges https://github.com/espressif/esp-mqtt/pull/117
This commit is contained in:
Laurent Louf
2019-05-03 12:06:46 +02:00
committed by Marius Vikhammer
parent 2b04d177c7
commit 2e0e93a2d3

View File

@@ -449,8 +449,11 @@ mqtt_message_t *mqtt_msg_publish(mqtt_connection_t *connection, const char *topi
connection->message.length = connection->buffer_length;
connection->message.fragmented_msg_total_length = data_length + connection->message.fragmented_msg_data_offset;
} else {
memcpy(connection->buffer + connection->message.length, data, data_length);
connection->message.length += data_length;
if (data != NULL)
{
memcpy(connection->buffer + connection->message.length, data, data_length);
connection->message.length += data_length;
}
connection->message.fragmented_msg_total_length = 0;
}
return fini_message(connection, MQTT_MSG_TYPE_PUBLISH, 0, qos, retain);