diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2020-02-19 23:59:18 +0100 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2020-02-19 19:49:30 -0800 |
commit | e761d00ddd68560e0f2b9d2f8650594978fa1168 (patch) | |
tree | ec13b26332d29b90bf096489b9c280c03ee28652 /commands | |
parent | c6f73ae144566dff0d4a6ae5f803a72e4b64281b (diff) | |
download | subsurface-e761d00ddd68560e0f2b9d2f8650594978fa1168.tar.gz |
undo: don't add dive to null-trip
In moveDiveToTrip(), the dive was first removed from its old trip
and then added to the new trip. This function is also used to
remove the dive from its trip (by moving it to the "null-trip"
if you whish). Even in that case add_dive_to_trip() was called.
The only reason why this didn't crash is that add_dive_to_trip()
checks whether old and new trip are the same. This is the case
when adding to the "null-trip", since the dive was removed from
the trip just before.
To cut a long story short, to trust on add_dive_to_trip() not
crashing if moving from the null-trip to the null-trip is
way to subtly. If we remove a dive from its trip, don't call
add_dive_to_trip() in the first place.
Reported-by: Dirk Hohndel <dirk@hohndel.org>
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'commands')
-rw-r--r-- | commands/command_divelist.cpp | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/commands/command_divelist.cpp b/commands/command_divelist.cpp index 6eac339f2..eedac4b6e 100644 --- a/commands/command_divelist.cpp +++ b/commands/command_divelist.cpp @@ -271,7 +271,8 @@ static OwningTripPtr moveDiveToTrip(DiveToTrip &diveToTrip) // Store old trip and get new trip we should associate this dive with std::swap(trip, diveToTrip.trip); - add_dive_to_trip(diveToTrip.dive, trip); + if (trip) + add_dive_to_trip(diveToTrip.dive, trip); invalidate_dive_cache(diveToTrip.dive); // Ensure that dive is written in git_save() return res; } |