Fix exception if no MQTT data

This commit is contained in:
Theo Arends 2018-03-03 19:04:33 +01:00
parent a16e2316b3
commit 15886c1df3
24 changed files with 11 additions and 8 deletions

View File

@ -185,9 +185,10 @@ bool TasmotaMqtt::Connected()
void TasmotaMqtt::_onMqttDataCb(const char* topic, uint32_t topic_len, const char* data, uint32_t data_len)
{
char topic_copy[topic_len];
char topic_copy[topic_len +1];
memcpy(topic_copy, topic, topic_len);
topic_copy[topic_len] = 0;
memcpy(topic_copy, topic, topic_len);
topic_copy[topic_len] = 0;
if (0 == data_len) data = (const char*)&topic_copy + topic_len;
onMqttDataCb((char*)topic_copy, (byte*)data, data_len);
}

View File

@ -154,12 +154,14 @@ void MqttDisconnectedCb()
MqttDisconnected(MqttClient->getState()); // status codes are documented in file mqtt.h as tConnState
}
void MqttMyDataCb(const char* topic, uint32_t topic_len, const char *data, uint32_t data_len)
void MqttMyDataCb(const char* topic, uint32_t topic_len, const char* data, uint32_t data_len)
{
char topicCpy[topic_len];
memcpy(topicCpy, topic, topic_len);
topicCpy[topic_len] = 0;
MqttDataHandler((char*)topicCpy, (byte*)data, data_len);
char topic_copy[topic_len +1];
memcpy(topic_copy, topic, topic_len);
topic_copy[topic_len] = 0;
if (0 == data_len) data = (const char*)&topic_copy + topic_len;
MqttDataHandler((char*)topic_copy, (byte*)data, data_len);
}
void MqttSubscribeLib(char *topic)