don't allocate ariable size on stack

This commit is contained in:
MichaelDvP
2026-05-18 20:55:57 +02:00
parent 3962adc911
commit 0dacd2c71f

View File

@@ -572,12 +572,11 @@ bool TxService::send_raw(const char * telegram_data) {
return false; return false;
} }
// since the telegram data is a const, make a copy. add 1 to grab the \0 EOS // since the telegram data is a const, make a copy
char telegram[strlen(telegram_data) + 1]; char * telegram = strdup(telegram_data);
strlcpy(telegram, telegram_data, sizeof(telegram));
uint8_t count = 0; uint8_t count = 0;
uint8_t data[2 + strlen(telegram) / 3]; uint8_t data[256]; // max raw telegram length
// get values // get values
char * p = strtok(telegram, " ,"); // delimiter char * p = strtok(telegram, " ,"); // delimiter
@@ -585,7 +584,7 @@ bool TxService::send_raw(const char * telegram_data) {
data[count++] = (uint8_t)strtol(p, 0, 16); data[count++] = (uint8_t)strtol(p, 0, 16);
p = strtok(nullptr, " ,"); p = strtok(nullptr, " ,");
} }
free(telegram);
// check valid length // check valid length
if (count < 4) { if (count < 4) {
return false; return false;