[PATCH] Don't try to malloc a zero sized list

Anton Lundin glance at acc.umu.se
Thu Dec 11 15:31:32 PST 2014


If we tried to copy a divecomputer without samples, we where to malloc a
zero sized blob. dives/test15.xml triggered this and it was found with
valgrind.

Signed-off-by: Anton Lundin <glance at acc.umu.se>
---
 dive.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/dive.c b/dive.c
index bb92818..f5f4b28 100644
--- a/dive.c
+++ b/dive.c
@@ -597,7 +597,7 @@ void copy_samples(struct divecomputer *s, struct divecomputer *d)
 {
 	/* instead of carefully copying them one by one and calling add_sample
 	 * over and over again, let's just copy the whole blob */
-	if (!s || !d)
+	if (!s || !d || !s->samples)
 		return;
 	int nr = s->samples;
 	d->samples = nr;
-- 
2.1.0



More information about the subsurface mailing list