summaryrefslogtreecommitdiffstats
path: root/dive.c
diff options
context:
space:
mode:
Diffstat (limited to 'dive.c')
-rw-r--r--dive.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/dive.c b/dive.c
index da80044ed..0351b8ba6 100644
--- a/dive.c
+++ b/dive.c
@@ -21,11 +21,13 @@ void add_event(struct divecomputer *dc, int time, int type, int flags, int value
ev->type = type;
ev->flags = flags;
ev->value = value;
- ev->next = NULL;
p = &dc->events;
- while (*p)
+
+ /* insert in the sorted list of events */
+ while (*p && (*p)->time.seconds < time)
p = &(*p)->next;
+ ev->next = *p;
*p = ev;
remember_event(name);
}