summaryrefslogtreecommitdiffstats
path: root/subsurface-core/dive.c
diff options
context:
space:
mode:
Diffstat (limited to 'subsurface-core/dive.c')
-rw-r--r--subsurface-core/dive.c35
1 files changed, 25 insertions, 10 deletions
diff --git a/subsurface-core/dive.c b/subsurface-core/dive.c
index 083767582..8fc9e993b 100644
--- a/subsurface-core/dive.c
+++ b/subsurface-core/dive.c
@@ -58,7 +58,7 @@ int event_gasmix_redundant(struct event *ev)
he == ev->gas.mix.he.permille;
}
-struct event *add_event(struct divecomputer *dc, int time, int type, int flags, int value, const char *name)
+struct event *add_event(struct divecomputer *dc, unsigned int time, int type, int flags, int value, const char *name)
{
int gas_index = -1;
struct event *ev, **p;
@@ -738,7 +738,8 @@ void per_cylinder_mean_depth(struct dive *dive, struct divecomputer *dc, int *me
{
int i;
int depthtime[MAX_CYLINDERS] = { 0, };
- int lasttime = 0, lastdepth = 0;
+ uint32_t lasttime = 0;
+ int lastdepth = 0;
int idx = 0;
for (i = 0; i < MAX_CYLINDERS; i++)
@@ -765,7 +766,7 @@ void per_cylinder_mean_depth(struct dive *dive, struct divecomputer *dc, int *me
dc = fake_dc(dc, false);
for (i = 0; i < dc->samples; i++) {
struct sample *sample = dc->sample + i;
- int time = sample->time.seconds;
+ uint32_t time = sample->time.seconds;
int depth = sample->depth.mm;
/* Make sure to move the event past 'lasttime' */
@@ -2619,7 +2620,8 @@ static struct divetag *taglist_add_divetag(struct tag_entry **tag_list, struct d
struct divetag *taglist_add_tag(struct tag_entry **tag_list, const char *tag)
{
- int i = 0, is_default_tag = 0;
+ size_t i = 0;
+ int is_default_tag = 0;
struct divetag *ret_tag, *new_tag;
const char *translation;
new_tag = malloc(sizeof(struct divetag));
@@ -2675,7 +2677,7 @@ static void taglist_merge(struct tag_entry **dst, struct tag_entry *src1, struct
void taglist_init_global()
{
- int i;
+ size_t i;
for (i = 0; i < sizeof(default_tags) / sizeof(char *); i++)
taglist_add_tag(&g_tag_list, default_tags[i]);
@@ -2846,7 +2848,7 @@ struct dive *merge_dives(struct dive *a, struct dive *b, int offset, bool prefer
MERGE_TXT(res, a, b, divemaster);
MERGE_MAX(res, a, b, rating);
MERGE_TXT(res, a, b, suit);
- MERGE_MIN(res, a, b, number);
+ MERGE_MAX(res, a, b, number);
MERGE_NONZERO(res, a, b, cns);
MERGE_NONZERO(res, a, b, visibility);
MERGE_NONZERO(res, a, b, picture_list);
@@ -2920,7 +2922,8 @@ static void force_fixup_dive(struct dive *d)
*/
static int split_dive_at(struct dive *dive, int a, int b)
{
- int i, t, nr;
+ int i, nr;
+ uint32_t t;
struct dive *d1, *d2;
struct divecomputer *dc1, *dc2;
struct event *event, **evp;
@@ -3371,7 +3374,7 @@ void dive_set_geodata_from_picture(struct dive *dive, struct picture *picture)
}
}
-static void picture_free(struct picture *picture)
+void picture_free(struct picture *picture)
{
if (!picture)
return;
@@ -3380,6 +3383,18 @@ static void picture_free(struct picture *picture)
free(picture);
}
+// When handling pictures in different threads, we need to copy them so we don't
+// run into problems when the main thread frees the picture.
+
+struct picture *clone_picture(struct picture *src)
+{
+ struct picture *dst;
+
+ dst = alloc_picture();
+ copy_pl(src, dst);
+ return dst;
+}
+
void dive_remove_picture(char *filename)
{
struct picture **picture = &current_dive->picture_list;
@@ -3415,7 +3430,7 @@ void make_first_dc()
}
/* always acts on the current dive */
-int count_divecomputers(void)
+unsigned int count_divecomputers(void)
{
int ret = 1;
struct divecomputer *dc = current_dive->dc.next;
@@ -3455,7 +3470,7 @@ void delete_current_divecomputer(void)
/* helper function to make it easier to work with our structures
* we don't interpolate here, just use the value from the last sample up to that time */
-int get_depth_at_time(struct divecomputer *dc, int time)
+int get_depth_at_time(struct divecomputer *dc, unsigned int time)
{
int depth = 0;
if (dc && dc->sample)