mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Fix crash in DiveComputerList::addDC() when importing from DM4.
DiveComputerList::getExact() created a temporary QList with the DiveComputerNodes matching a specific model. A pointer to a node in the list was returned, which becomes invalid when the list goes out of scope and gets destroyed. Causing a crash when the model strings are compared later. Instead of using contains() and creating a temporary list, we can just use an iterator, which should be both faster and safer. The crash is easy to trigger with DM4 imports, but can probably be triggered in other cases too. Similar problem with DiveComputerList::get(). Signed-off-by: Michael Andreen <harv@ruin.nu> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
67fec4da70
commit
396b2d1031
1 changed files with 6 additions and 10 deletions
16
qthelper.cpp
16
qthelper.cpp
|
@ -35,21 +35,17 @@ bool DiveComputerNode::changesValues(const DiveComputerNode &b) const
|
|||
|
||||
const DiveComputerNode *DiveComputerList::getExact(QString m, uint32_t d)
|
||||
{
|
||||
if (dcMap.contains(m)) {
|
||||
QList<DiveComputerNode> values = dcMap.values(m);
|
||||
for (int i = 0; i < values.size(); i++)
|
||||
if (values.at(i).deviceId == d)
|
||||
return &values.at(i);
|
||||
}
|
||||
for (QMap<QString,DiveComputerNode>::iterator it = dcMap.find(m); it != dcMap.end() && it.key() == m; ++it)
|
||||
if (it->deviceId == d)
|
||||
return &*it;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const DiveComputerNode *DiveComputerList::get(QString m)
|
||||
{
|
||||
if (dcMap.contains(m)) {
|
||||
QList<DiveComputerNode> values = dcMap.values(m);
|
||||
return &values.at(0);
|
||||
}
|
||||
QMap<QString,DiveComputerNode>::iterator it = dcMap.find(m);
|
||||
if (it != dcMap.end())
|
||||
return &*it;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue