summaryrefslogtreecommitdiffstats
path: root/subsurface-core
diff options
context:
space:
mode:
Diffstat (limited to 'subsurface-core')
-rw-r--r--subsurface-core/device.c10
-rw-r--r--subsurface-core/device.h2
-rw-r--r--subsurface-core/dive.c2
3 files changed, 9 insertions, 5 deletions
diff --git a/subsurface-core/device.c b/subsurface-core/device.c
index bc1a2f681..6c4452f78 100644
--- a/subsurface-core/device.c
+++ b/subsurface-core/device.c
@@ -108,12 +108,16 @@ static void fill_samples_no_avg(struct sample *s, int max_d, int max_t, double s
}
}
-struct divecomputer *fake_dc(struct divecomputer *dc)
+struct divecomputer *fake_dc(struct divecomputer *dc, bool alloc)
{
- static struct sample fake[6];
+ static struct sample fake_samples[6];
static struct divecomputer fakedc;
+ struct sample *fake = fake_samples;
fakedc = (*dc);
+ if (alloc)
+ fake = malloc(sizeof(fake_samples));
+
fakedc.sample = fake;
fakedc.samples = 6;
@@ -122,7 +126,7 @@ struct divecomputer *fake_dc(struct divecomputer *dc)
int max_d = dc->maxdepth.mm;
int avg_d = dc->meandepth.mm;
- memset(fake, 0, sizeof(fake));
+ memset(fake, 0, sizeof(fake_samples));
fake[5].time.seconds = max_t;
if (!max_t || !max_d)
return &fakedc;
diff --git a/subsurface-core/device.h b/subsurface-core/device.h
index 9ff2ce23a..8a00b96d3 100644
--- a/subsurface-core/device.h
+++ b/subsurface-core/device.h
@@ -6,7 +6,7 @@
extern "C" {
#endif
-extern struct divecomputer *fake_dc(struct divecomputer *dc);
+extern struct divecomputer *fake_dc(struct divecomputer *dc, bool alloc);
extern void create_device_node(const char *model, uint32_t deviceid, const char *serial, const char *firmware, const char *nickname);
extern void call_for_each_dc(void *f, void (*callback)(void *, const char *, uint32_t,
const char *, const char *, const char *), bool select_only);
diff --git a/subsurface-core/dive.c b/subsurface-core/dive.c
index fd0d25989..85ad3f597 100644
--- a/subsurface-core/dive.c
+++ b/subsurface-core/dive.c
@@ -762,7 +762,7 @@ void per_cylinder_mean_depth(struct dive *dive, struct divecomputer *dc, int *me
return;
}
if (!dc->samples)
- dc = fake_dc(dc);
+ dc = fake_dc(dc, false);
for (i = 0; i < dc->samples; i++) {
struct sample *sample = dc->sample + i;
int time = sample->time.seconds;