mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-28 05:00:20 +00:00
Location model: treat invalid indexes gracefully
There have been crash reports in DiveSiteSortedModel::allSiteNames(). The only conceivable reason that this crashes is that the core knows about more sites than the model and therefore on mapToSource() we get an invalid index, which is translated to -1. Accessing the name of that dive site will crash. Handle such invalid indexes gracefully. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
309a8c5b14
commit
f18ea2e3b6
1 changed files with 7 additions and 0 deletions
|
@ -227,6 +227,13 @@ QStringList DiveSiteSortedModel::allSiteNames() const
|
|||
int num = rowCount();
|
||||
for (int i = 0; i < num; i++) {
|
||||
int idx = mapToSource(index(i, 0)).row();
|
||||
// This shouldn't happen, but if model and core get out of sync,
|
||||
// (more precisely: the core has more sites than the model is aware of),
|
||||
// we might get an invalid index.
|
||||
if (idx < 0 || idx > dive_site_table.nr) {
|
||||
fprintf(stderr, "DiveSiteSortedModel::allSiteNames(): invalid index");
|
||||
continue;
|
||||
}
|
||||
locationNames << QString(dive_site_table.dive_sites[idx]->name);
|
||||
}
|
||||
return locationNames;
|
||||
|
|
Loading…
Reference in a new issue