mirror of
https://github.com/opentx/opentx.git
synced 2025-07-17 13:25:20 +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:
parent
d287027502
commit
370f954e10
1 changed files with 25 additions and 18 deletions
|
@ -140,28 +140,35 @@ class ModelsList
|
|||
clear();
|
||||
|
||||
FRESULT result = f_open(&file, RADIO_MODELSLIST_PATH, FA_OPEN_EXISTING | FA_READ);
|
||||
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] == ']') {
|
||||
line[len-1] = '\0';
|
||||
category = new ModelsCategory(&line[1]);
|
||||
categories.push_back(category);
|
||||
}
|
||||
else if (category && len > 0) {
|
||||
ModelCell * model = new ModelCell(line);
|
||||
category->push_back(model);
|
||||
if (!strncmp(line, g_eeGeneral.currModelFilename, LEN_MODEL_FILENAME)) {
|
||||
currentCategory = category;
|
||||
currentModel = model;
|
||||
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] == ']') {
|
||||
line[len-1] = '\0';
|
||||
category = new ModelsCategory(&line[1]);
|
||||
categories.push_back(category);
|
||||
}
|
||||
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;
|
||||
currentModel = model;
|
||||
}
|
||||
}
|
||||
}
|
||||
f_close(&file);
|
||||
}
|
||||
|
||||
if (categories.size() == 0) {
|
||||
category = new ModelsCategory("Models");
|
||||
categories.push_back(category);
|
||||
}
|
||||
|
||||
f_close(&file);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue