Skip to content
Snippets Groups Projects
Commit 72022106 authored by Rob Swindell's avatar Rob Swindell :speech_balloon:
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 d2320849
No related branches found
No related tags found
No related merge requests found
......@@ -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);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment