1
0
Fork 0
mirror of https://github.com/opentx/opentx.git synced 2025-07-17 21:35:27 +03:00

[Horus] #3599 - Crash in case of 0 model categories in models.txt (which happens at least when SD is not present)

This commit is contained in:
Bertrand Songis 2016-06-15 19:57:35 +02:00
parent d287027502
commit 370f954e10

View file

@ -140,10 +140,7 @@ class ModelsList
clear();
FRESULT result = f_open(&file, RADIO_MODELSLIST_PATH, FA_OPEN_EXISTING | FA_READ);
if (result != FR_OK) {
return false;
}
if (result == FR_OK) {
while (readNextLine(line, LEN_MODEL_FILENAME)) {
int len = strlen(line); // TODO could be returned by readNextLine
if (len > 2 && line[0] == '[' && line[len-1] == ']') {
@ -151,8 +148,12 @@ class ModelsList
category = new ModelsCategory(&line[1]);
categories.push_back(category);
}
else if (category && len > 0) {
else if (len > 0) {
ModelCell * model = new ModelCell(line);
if (!category) {
category = new ModelsCategory("Unknown");
categories.push_back(category);
}
category->push_back(model);
if (!strncmp(line, g_eeGeneral.currModelFilename, LEN_MODEL_FILENAME)) {
currentCategory = category;
@ -160,8 +161,14 @@ class ModelsList
}
}
}
f_close(&file);
}
if (categories.size() == 0) {
category = new ModelsCategory("Models");
categories.push_back(category);
}
return true;
}