mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2026-01-27 09:09:25 +03:00
fix standalone/make, fix HA avty, fix deprecated arduinojson, update packages
This commit is contained in:
@@ -237,12 +237,20 @@ const char * Command::parse_command_string(const char * command, int8_t & id) {
|
||||
const char * cmd_org = command;
|
||||
int8_t id_org = id;
|
||||
|
||||
// convert cmd to lowercase and compare
|
||||
char * lowerCmd = strdup(command);
|
||||
for (char * p = lowerCmd; *p; p++) {
|
||||
*p = tolower(*p);
|
||||
// Optimized: Use stack buffer instead of strdup() to avoid heap allocation
|
||||
// Most command strings are short, 64 bytes is more than enough
|
||||
char lowerCmd[64];
|
||||
size_t len = strlen(command);
|
||||
if (len >= sizeof(lowerCmd)) {
|
||||
len = sizeof(lowerCmd) - 1; // truncate if too long (rare case)
|
||||
}
|
||||
|
||||
// Convert to lowercase in place using stack buffer
|
||||
for (size_t i = 0; i < len; i++) {
|
||||
lowerCmd[i] = tolower(command[i]);
|
||||
}
|
||||
lowerCmd[len] = '\0';
|
||||
|
||||
// check prefix and valid number range, also check 'id'
|
||||
if (!strncmp(lowerCmd, "hc", 2) && command[2] >= '1' && command[2] <= '8') {
|
||||
id = command[2] - '0';
|
||||
@@ -279,7 +287,7 @@ const char * Command::parse_command_string(const char * command, int8_t & id) {
|
||||
command += 3;
|
||||
}
|
||||
|
||||
free(lowerCmd);
|
||||
// No free() needed - stack buffer is automatically cleaned up
|
||||
|
||||
// return original if no seperator
|
||||
if (command[0] != '/' && command[0] != '.') {
|
||||
|
||||
Reference in New Issue
Block a user