From 4795e1b6ce8a957bde70f5ca41d7e347f2c24743 Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Sun, 12 Jul 2015 22:13:22 +0200 Subject: [PATCH] Prevent a zero length memory allocation. In theory this shouldn't be possible, but it doesn't hurt to check the length explicitely. --- src/oceanic_common.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/oceanic_common.c b/src/oceanic_common.c index 2dde296..c51836f 100644 --- a/src/oceanic_common.c +++ b/src/oceanic_common.c @@ -315,6 +315,11 @@ oceanic_common_device_foreach (dc_device_t *abstract, dc_dive_callback_t callbac rb_logbook_page_size; device_event_emit (abstract, DC_EVENT_PROGRESS, &progress); + // Exit if there are no dives. + if (rb_logbook_page_size == 0) { + return DC_STATUS_SUCCESS; + } + // Memory buffer for the logbook entries. unsigned char *logbooks = (unsigned char *) malloc (rb_logbook_page_size); if (logbooks == NULL)