add check fto translated_word for empty arrays, to be crash safe

This commit is contained in:
Proddy
2022-10-02 15:53:26 +02:00
parent cd67ab03ff
commit ae5fb26387

View File

@@ -707,6 +707,11 @@ std::string Helpers::translated_word(const char * const * strings, bool to_lower
uint8_t language_index = EMSESP::system_.language_index();
uint8_t index = 0;
// check for empty
if (!strings) {
return ""; // it's a nullptr with no translations, return empty to prevent unwanted crash
}
// see how many translations we have for this entity. if there is no translation for this, revert to EN
if (Helpers::count_items(strings) >= language_index + 1 && strlen(strings[language_index])) {
index = language_index;