From 9366e36309cd6f027aa3e5338160753e93cb9b7d Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Mon, 17 Sep 2012 20:44:34 +0200 Subject: [PATCH] Finish immediately if there are no dives available. When trying to continue when no dives are available, malloc() will be called to allocate zero bytes. The result is implementation defined and may return a NULL pointer. Since that would be interpreted as an error, it's safer to finish immediately. --- src/hw_frog.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/hw_frog.c b/src/hw_frog.c index 3557cee..b9db582 100644 --- a/src/hw_frog.c +++ b/src/hw_frog.c @@ -418,6 +418,12 @@ hw_frog_device_foreach (dc_device_t *abstract, dc_dive_callback_t callback, void progress.maximum = (RB_LOGBOOK_SIZE * RB_LOGBOOK_COUNT) + size; device_event_emit (abstract, DC_EVENT_PROGRESS, &progress); + // Finish immediately if there are no dives available. + if (ndives == 0) { + free (header); + return DC_STATUS_SUCCESS; + } + // Allocate enough memory for the largest dive. unsigned char *profile = malloc (maxsize); if (profile == NULL) {