Commit 7ef33bc8 authored by Rob Swindell's avatar Rob Swindell 💬
Browse files

Fix crash in mqtt_errormsg() when MQTT is disabled

Should fix the segfault reported by NeoArata_ in #synchronet

Also include singular/plural error/s in server status messages.
parent bde27447
Pipeline #3596 passed with stage
in 6 minutes and 29 seconds
......@@ -544,7 +544,7 @@ int mqtt_server_state(struct mqtt* mqtt, enum server_state state)
char tmp[256];
char errors[64] = "";
if(mqtt->error_count)
snprintf(errors, sizeof(errors), "%lu errors", mqtt->error_count);
snprintf(errors, sizeof(errors), "%lu error%s", mqtt->error_count, mqtt->error_count > 1 ? "s" : "");
char served[64] = "";
if(mqtt->served)
snprintf(served, sizeof(served), "%lu served", mqtt->served);
......@@ -567,7 +567,7 @@ int mqtt_server_state(struct mqtt* mqtt, enum server_state state)
int mqtt_errormsg(struct mqtt* mqtt, int level, const char* msg)
{
if(mqtt == NULL)
if(mqtt == NULL || mqtt->cfg == NULL)
return MQTT_FAILURE;
++mqtt->error_count;
mqtt_pub_uintval(mqtt, TOPIC_SERVER, "error_count", mqtt->error_count);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment