From f93b2afcc895a2c04c5624142fbc33856c04e286 Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Tue, 18 Feb 2020 22:13:07 +0100 Subject: [PATCH] Improve the empty logbook ringbuffer detection If all the entries in the logbook ringbuffer happen to be empty, the ringbuffer end pointer will not have a valid value. Creating the ringbuffer stream will fail, and an error will be returned to the caller. Fixed by adding an extra check, and exit if there are no dives. --- src/oceanic_common.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/oceanic_common.c b/src/oceanic_common.c index 4a42300..728101f 100644 --- a/src/oceanic_common.c +++ b/src/oceanic_common.c @@ -417,6 +417,11 @@ oceanic_common_device_profile (dc_device_t *abstract, dc_event_progress_t *progr progress->maximum -= (layout->rb_profile_end - layout->rb_profile_begin) - rb_profile_size; device_event_emit (abstract, DC_EVENT_PROGRESS, progress); + // Exit if there are no dives. + if (rb_profile_size == 0) { + return DC_STATUS_SUCCESS; + } + // Create the ringbuffer stream. dc_rbstream_t *rbstream = NULL; rc = dc_rbstream_new (&rbstream, abstract, PAGESIZE, PAGESIZE * device->multipage, layout->rb_profile_begin, layout->rb_profile_end, rb_profile_end);