mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-30 22:20:21 +00:00
undo: fix RemoveEvent if we can't find the event
We check for the event, but then access it anyway even if it doesn't exist. Should not happen, but let's be safe. Found by Coverity. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
5c6ca2c1ce
commit
e305546046
1 changed files with 6 additions and 4 deletions
|
@ -115,19 +115,21 @@ void RenameEvent::undoit()
|
||||||
redoit();
|
redoit();
|
||||||
}
|
}
|
||||||
|
|
||||||
RemoveEvent::RemoveEvent(struct dive *d, int dcNr, int idx) : EventBase(d, dcNr),
|
RemoveEvent::RemoveEvent(struct dive *d, int dcNr, int idxIn) : EventBase(d, dcNr),
|
||||||
idx(idx), cylinder(-1)
|
idx(idxIn), cylinder(-1)
|
||||||
{
|
{
|
||||||
struct divecomputer *dc = d->get_dc(dcNr);
|
struct divecomputer *dc = d->get_dc(dcNr);
|
||||||
event *ev = get_event(dc, idx);
|
event *ev = get_event(dc, idx);
|
||||||
if (ev && (ev->type == SAMPLE_EVENT_GASCHANGE2 || ev->type == SAMPLE_EVENT_GASCHANGE))
|
if (!ev)
|
||||||
|
idx = -1;
|
||||||
|
if (ev->type == SAMPLE_EVENT_GASCHANGE2 || ev->type == SAMPLE_EVENT_GASCHANGE)
|
||||||
cylinder = ev->gas.index;
|
cylinder = ev->gas.index;
|
||||||
setText(Command::Base::tr("Remove %1 event").arg(ev->name.c_str()));
|
setText(Command::Base::tr("Remove %1 event").arg(ev->name.c_str()));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RemoveEvent::workToBeDone()
|
bool RemoveEvent::workToBeDone()
|
||||||
{
|
{
|
||||||
return true;
|
return idx >= 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RemoveEvent::redoit()
|
void RemoveEvent::redoit()
|
||||||
|
|
Loading…
Reference in a new issue