diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2018-10-15 15:37:50 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2018-10-15 12:50:44 -0400 |
commit | a58908df8e8a5cb21fd08cd495f0099d3f99b1f9 (patch) | |
tree | d3569f3f52f3bb0902192b9e7bd176a6311f4c88 /core | |
parent | 2775e7e9910ec76f47f7568f02a06c84c01265fa (diff) | |
download | subsurface-a58908df8e8a5cb21fd08cd495f0099d3f99b1f9.tar.gz |
Dive import: reset current_dive in process_imported_dives()
process_imported_dives() might delete the currently selected
dives. This could lead to use-after-free problems. Therefore,
reset the currently selected dive to the last dive.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'core')
-rw-r--r-- | core/divelist.c | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/core/divelist.c b/core/divelist.c index 922c04e43..ec088a87e 100644 --- a/core/divelist.c +++ b/core/divelist.c @@ -1600,6 +1600,9 @@ void process_imported_dives(struct dive_table *import_table, bool prefer_importe if (!sequence_changed) try_to_renumber(preexisting); + /* We might have deleted the old selected dive. + * Choose the newest dive as selected (if any) */ + current_dive = dive_table.nr > 0 ? dive_table.dives[dive_table.nr - 1] : NULL; mark_divelist_changed(true); } |