From 325b8bba35c339d626071b3feedbc6140774a725 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Wed, 18 Jul 2018 19:31:59 +0200 Subject: Undo: remember deleted trip in UndoRemoveDivesFromTrip::undo() If the last dive of a trip is removed, the trip is deleted. On redo the dive is added to a non existing trip, leading to a segfault. Therefore, keep a copy of the trip to reinstate it on redo. Note: this cannot work for a sequence of multiple commands. One would have to rewrite the whole undo-history. Nevertheless, let's do this as a stop-gap measure. Signed-off-by: Berthold Stoeger --- core/dive.h | 1 + core/divelist.c | 13 +++++++++++++ 2 files changed, 14 insertions(+) (limited to 'core') diff --git a/core/dive.h b/core/dive.h index 1b58eef4c..569232a38 100644 --- a/core/dive.h +++ b/core/dive.h @@ -507,6 +507,7 @@ extern void delete_single_dive(int idx); extern void add_single_dive(int idx, struct dive *dive); extern void insert_trip(dive_trip_t **trip); +extern struct dive_trip *clone_empty_trip(struct dive_trip *trip); extern const struct units SI_units, IMPERIAL_units; diff --git a/core/divelist.c b/core/divelist.c index 7291de23e..a9b793517 100644 --- a/core/divelist.c +++ b/core/divelist.c @@ -727,6 +727,19 @@ void insert_trip(dive_trip_t **dive_trip_p) #endif } +/* create a copy of a dive trip, but don't add any dives. */ +dive_trip_t *clone_empty_trip(dive_trip_t *trip) +{ + dive_trip_t *copy = malloc(sizeof(struct dive_trip)); + *copy = *trip; + copy->location = copy_string(trip->location); + copy->notes = copy_string(trip->notes); + copy->nrdives = 0; + copy->next = NULL; + copy->dives = NULL; + return copy; +} + static void delete_trip(dive_trip_t *trip) { dive_trip_t **p, *tmp; -- cgit v1.2.3-70-g09d2