summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--dive.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/dive.c b/dive.c
index 7ec4bc918..78224d82c 100644
--- a/dive.c
+++ b/dive.c
@@ -602,6 +602,14 @@ void copy_samples(struct divecomputer *s, struct divecomputer *d)
int nr = s->samples;
d->samples = nr;
d->alloc_samples = nr;
+ // We expect to be able to read the memory in the other end of the pointer
+ // if its a valid pointer, so don't expect malloc() to return NULL for
+ // zero-sized malloc, do it ourselves.
+ d->sample = NULL;
+
+ if(!nr)
+ return;
+
d->sample = malloc(nr * sizeof(struct sample));
if (d->sample)
memcpy(d->sample, s->sample, nr * sizeof(struct sample));