mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Rename event: correctly replace event with new one
I don't like that the event structure includes the variable length array. That really makes it a pain to change the name of an event (on the flip side, freeing events is easier I guess). Anyway, to correctly rename an event we need to actually remove the event from the correct dc and then add a new event with the new name. The previous code was insane (it only worked if the new name was of smaller or equal length, otherwise it had a beautiful buffer overflow). And of course we need to do this both for the current_dive and the displayed_dive. Fixes #616 Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
f9b18b9bfb
commit
74616cdddf
3 changed files with 31 additions and 3 deletions
23
dive.c
23
dive.c
|
@ -75,6 +75,29 @@ void remove_event(struct event* event)
|
|||
}
|
||||
}
|
||||
|
||||
/* since the name is an array as part of the structure (how silly is that?) we
|
||||
* have to actually remove the existing event and replace it with a new one.
|
||||
* WARNING, WARNING... this may end up freeing event in case that event is indeed
|
||||
* WARNING, WARNING... part of this divecomputer on this dive! */
|
||||
void update_event_name(struct dive *d, struct event* event, char *name)
|
||||
{
|
||||
if (!d || !event)
|
||||
return;
|
||||
struct divecomputer *dc = get_dive_dc(d, dc_number);
|
||||
if (!dc)
|
||||
return;
|
||||
struct event **removep = &dc->events;
|
||||
struct event *remove;
|
||||
while ((*removep)->next && !same_event(*removep, event))
|
||||
removep = &(*removep)->next;
|
||||
if (!same_event(*removep, event))
|
||||
return;
|
||||
remove = *removep;
|
||||
*removep = (*removep)->next;
|
||||
add_event(dc, event->time.seconds, event->type, event->flags, event->value, name);
|
||||
free(remove);
|
||||
}
|
||||
|
||||
/* this returns a pointer to static variable - so use it right away after calling */
|
||||
struct gasmix *get_gasmix_from_event(struct event *ev)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue