divelog: fix erroneous use of std::move()

This has to be applied to the object, not the pointer to the object.
Fixes a double-free crash introduced in 8cd451f.

Alternatively, we could use std::swap() for C++98 charm and perhaps
better readability for people unfamiliar with C++11. Nowadays,
std::move() is more idiomatic though. Shrug.

Reported-by: Michael Keller <github@ike.ch>
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2023-04-18 09:31:42 +02:00 committed by bstoeger
parent a38ea971a0
commit a8d2b2ff70

View file

@ -40,8 +40,8 @@ divelog::divelog(divelog &&log) :
dives(new dive_table), dives(new dive_table),
trips(new trip_table), trips(new trip_table),
sites(new dive_site_table), sites(new dive_site_table),
devices(std::move(log.devices)), devices(new device_table),
filter_presets(std::move(log.filter_presets)) filter_presets(new filter_preset_table)
{ {
*dives = empty_dive_table; *dives = empty_dive_table;
*trips = empty_trip_table; *trips = empty_trip_table;
@ -49,6 +49,8 @@ divelog::divelog(divelog &&log) :
move_dive_table(log.dives, dives); move_dive_table(log.dives, dives);
move_trip_table(log.trips, trips); move_trip_table(log.trips, trips);
move_dive_site_table(log.sites, sites); move_dive_site_table(log.sites, sites);
*devices = std::move(*log.devices);
*filter_presets = std::move(*log.filter_presets);
} }
struct divelog &divelog::operator=(divelog &&log) struct divelog &divelog::operator=(divelog &&log)
@ -56,8 +58,8 @@ struct divelog &divelog::operator=(divelog &&log)
move_dive_table(log.dives, dives); move_dive_table(log.dives, dives);
move_trip_table(log.trips, trips); move_trip_table(log.trips, trips);
move_dive_site_table(log.sites, sites); move_dive_site_table(log.sites, sites);
devices = std::move(log.devices); *devices = std::move(*log.devices);
filter_presets = std::move(log.filter_presets); *filter_presets = std::move(*log.filter_presets);
return *this; return *this;
} }