fix deviceName length (#2482), formatting

This commit is contained in:
MichaelDvP
2025-03-28 09:39:38 +01:00
parent c927e5f496
commit d405478a13

View File

@@ -975,7 +975,9 @@ void EMSESP::process_deviceName(std::shared_ptr<const Telegram> telegram) {
return;
}
char name[16];
uint8_t len = telegram->offset + telegram->message_length - 27;
// len including zero terminator, if there is one, otherwise copy to end of telegram
// https://github.com/emsesp/EMS-ESP32/discussions/2482#discussioncomment-12649817
uint8_t len = telegram->offset + telegram->message_length - 26;
strlcpy(name, (const char *)&telegram->message_data[27 - telegram->offset], len < 16 ? len : 16);
char * c = name;
while (isprint(*c)) {
@@ -1314,7 +1316,7 @@ bool EMSESP::add_device(const uint8_t device_id, const uint8_t product_id, const
flags = DeviceFlags::EMS_DEVICE_FLAG_CR120;
default_name = "CR120";
}
if (product_id == 158 && strncmp(version,"73",2) == 0) {
if (product_id == 158 && strncmp(version, "73", 2) == 0) {
flags = DeviceFlags::EMS_DEVICE_FLAG_HMC310;
default_name = "HMC310";
}