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