From e53e7cf96153f8475a771c1245e334fb48021cb4 Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Mon, 30 Nov 2020 19:57:21 +0100 Subject: [PATCH 1/2] Re-use the common error handling code There is no need to duplicate the error cleanup code everywhere. Break out of the while loop and cleanup at the end of the function. --- src/oceanic_common.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/oceanic_common.c b/src/oceanic_common.c index 9a7c2e2..d4802fc 100644 --- a/src/oceanic_common.c +++ b/src/oceanic_common.c @@ -504,9 +504,8 @@ oceanic_common_device_profile (dc_device_t *abstract, dc_event_progress_t *progr { ERROR (abstract->context, "Invalid ringbuffer pointer detected (0x%06x 0x%06x).", rb_entry_first, rb_entry_last); - dc_rbstream_free (rbstream); - free (profiles); - return DC_STATUS_DATAFORMAT; + status = DC_STATUS_DATAFORMAT; + break; } // Calculate the end pointer and the number of bytes. @@ -533,9 +532,8 @@ oceanic_common_device_profile (dc_device_t *abstract, dc_event_progress_t *progr rc = dc_rbstream_read (rbstream, progress, profiles + offset, rb_entry_size + gap); if (rc != DC_STATUS_SUCCESS) { ERROR (abstract->context, "Failed to read the dive."); - dc_rbstream_free (rbstream); - free (profiles); - return rc; + status = rc; + break; } remaining -= rb_entry_size + gap; @@ -570,7 +568,7 @@ oceanic_common_device_profile (dc_device_t *abstract, dc_event_progress_t *progr dc_rbstream_free (rbstream); free (profiles); - return DC_STATUS_SUCCESS; + return status; } From 9eddbe88be88bf9a6dfbbef5e7a74c9b6d0c23e9 Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Mon, 30 Nov 2020 20:25:27 +0100 Subject: [PATCH 2/2] Skip logbook entries with invalid pointers Since logbook entries with invalid ringbuffer pointers are considered a fatal error, the download is aborted. The result is that any remaining entries, located after the invalid entry, can't be downloaded at all. This can be avoided by skipping the problematic entry instead of aborting the download. --- src/oceanic_common.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/oceanic_common.c b/src/oceanic_common.c index d4802fc..51c234f 100644 --- a/src/oceanic_common.c +++ b/src/oceanic_common.c @@ -415,7 +415,7 @@ oceanic_common_device_profile (dc_device_t *abstract, dc_event_progress_t *progr ERROR (abstract->context, "Invalid ringbuffer pointer detected (0x%06x 0x%06x).", rb_entry_first, rb_entry_last); status = DC_STATUS_DATAFORMAT; - break; + continue; } // Calculate the end pointer and the number of bytes. @@ -505,7 +505,7 @@ oceanic_common_device_profile (dc_device_t *abstract, dc_event_progress_t *progr ERROR (abstract->context, "Invalid ringbuffer pointer detected (0x%06x 0x%06x).", rb_entry_first, rb_entry_last); status = DC_STATUS_DATAFORMAT; - break; + continue; } // Calculate the end pointer and the number of bytes.