mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-06 15:59:52 +03:00
add check fto translated_word for empty arrays, to be crash safe
This commit is contained in:
@@ -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 language_index = EMSESP::system_.language_index();
|
||||||
uint8_t index = 0;
|
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
|
// 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])) {
|
if (Helpers::count_items(strings) >= language_index + 1 && strlen(strings[language_index])) {
|
||||||
index = language_index;
|
index = language_index;
|
||||||
|
|||||||
Reference in New Issue
Block a user