From 4ba92e24ef0401f520d2de90255511672f0bfdc6 Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Tue, 28 Jun 2016 20:29:08 +0200 Subject: [PATCH] Fix a crash when no dives are present. To guard applications from divisions by zero, the progress event code asserts the maximum value should always be non-zero. The eonsteel does trigger this assert when there are no dives present. --- src/suunto_eonsteel.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/suunto_eonsteel.c b/src/suunto_eonsteel.c index 079c353..a84eaea 100644 --- a/src/suunto_eonsteel.c +++ b/src/suunto_eonsteel.c @@ -649,6 +649,7 @@ suunto_eonsteel_device_foreach(dc_device_t *abstract, dc_dive_callback_t callbac dc_buffer_t *file; char pathname[64]; unsigned int time; + unsigned int count = 0; dc_event_progress_t progress = EVENT_PROGRESS_INITIALIZER; if (get_file_list(eon, &de) < 0) @@ -661,8 +662,13 @@ suunto_eonsteel_device_foreach(dc_device_t *abstract, dc_dive_callback_t callbac devinfo.serial = array_convert_str2num(eon->version + 0x10, 16); device_event_emit (abstract, DC_EVENT_DEVINFO, &devinfo); + count = count_dir_entries(de); + if (count == 0) { + return DC_STATUS_SUCCESS; + } + file = dc_buffer_new(0); - progress.maximum = count_dir_entries(de); + progress.maximum = count; progress.current = 0; device_event_emit(abstract, DC_EVENT_PROGRESS, &progress);