diff --git a/lib/patrix/config.cpp b/lib/patrix/config.cpp index 393e017..ac9f866 100644 --- a/lib/patrix/config.cpp +++ b/lib/patrix/config.cpp @@ -128,7 +128,7 @@ bool configWriteBytes(int *address, uint8_t *data, size_t size) { break; } } - return b - data == size; + return (size_t) (b - data) == size; } bool configReadBytes(int *address, uint8_t *data, size_t size) { @@ -140,5 +140,5 @@ bool configReadBytes(int *address, uint8_t *data, size_t size) { break; } } - return b - data == size; + return (size_t) (b - data) == size; } diff --git a/lib/patrix/console.cpp b/lib/patrix/console.cpp index cb10909..833adc1 100644 --- a/lib/patrix/console.cpp +++ b/lib/patrix/console.cpp @@ -68,6 +68,10 @@ void consoleLoop() { void consoleHandle(char *cmd) { char *first = strtok(cmd, " "); + if (first == nullptr) { + _usage(); + return; + } if (strcmp(first, "help") == 0) { _usage(); } else if (strcmp(first, "wifi") == 0) { @@ -88,19 +92,18 @@ void consoleHandle(char *cmd) { } void _usage() { - info("help"); - info("info"); - info("debug"); - - info("reboot"); - info("config_reset"); - - info("wifi reconnect"); - info("wifi ssid "); - info("wifi pkey "); - - info("mqtt reconnect"); - info("mqtt host "); + info(R"(USAGE: + help + info + debug + reboot + config_reset + wifi reconnect + wifi ssid + wifi pkey + mqtt reconnect + mqtt host +)"); } void _debug() { @@ -117,6 +120,10 @@ void _reboot() { void _mqtt() { char *sub = strtok(nullptr, " "); + if (sub == nullptr) { + _usage(); + return; + } if (strcmp(sub, "reconnect") == 0) { info("Reconnecting MQTT..."); mqttDisconnect(); @@ -127,6 +134,10 @@ void _mqtt() { void _wifi() { char *sub = strtok(nullptr, " "); + if (sub == nullptr) { + _usage(); + return; + } if (strcmp(sub, "reconnect") == 0) { info("Reconnecting WiFi..."); wifiConnect(); @@ -139,6 +150,10 @@ void _wifi() { void _setConfigString(const char *name, bool allowEmpty) { char *value = strtok(nullptr, ""); + if (value == nullptr) { + _usage(); + return; + } if (!allowEmpty && strcmp(value, "") == 0) { error(R"(Value for "%s" cannot be empty!")", name); return; diff --git a/src/Fermenter.cpp b/src/Fermenter.cpp index e13c0b3..a8da776 100644 --- a/src/Fermenter.cpp +++ b/src/Fermenter.cpp @@ -82,6 +82,10 @@ void patrixLoop() { bool setDouble(const char *name, double *destinationPtr, double min, double max) { const char *valueStr = strtok(nullptr, ""); + if (valueStr == nullptr) { + _usage(); + return; + } if (valueStr == nullptr) { error("Missing value for \"%s\"", name); return false;