diff --git a/src/citizen_aqualand.c b/src/citizen_aqualand.c index 4d1817c..21894a5 100644 --- a/src/citizen_aqualand.c +++ b/src/citizen_aqualand.c @@ -152,13 +152,6 @@ citizen_aqualand_device_dump (dc_device_t *abstract, dc_buffer_t *buffer) dc_status_t status = DC_STATUS_SUCCESS; citizen_aqualand_device_t *device = (citizen_aqualand_device_t *) abstract; - // Erase the current contents of the buffer and - // pre-allocate the required amount of memory. - if (!dc_buffer_clear (buffer)) { - ERROR (abstract->context, "Insufficient buffer space available."); - return DC_STATUS_NOMEMORY; - } - status = dc_iostream_set_dtr (device->iostream, 1); if (status != DC_STATUS_SUCCESS) { ERROR (abstract->context, "Failed to set the DTR line."); diff --git a/src/cochran_commander.c b/src/cochran_commander.c index e21ec7e..bbf92c7 100644 --- a/src/cochran_commander.c +++ b/src/cochran_commander.c @@ -842,12 +842,6 @@ cochran_commander_device_dump (dc_device_t *abstract, dc_buffer_t *buffer) unsigned int config_size = sizeof(config); unsigned int size = device->layout->rb_profile_end - device->layout->rb_logbook_begin; - // Make sure buffer is good. - if (!dc_buffer_clear(buffer)) { - ERROR (abstract->context, "Uninitialized buffer."); - return DC_STATUS_INVALIDARGS; - } - // Reserve space if (!dc_buffer_resize(buffer, size)) { ERROR(abstract->context, "Insufficient buffer space available."); diff --git a/src/cressi_edy.c b/src/cressi_edy.c index 80e4fac..327b4aa 100644 --- a/src/cressi_edy.c +++ b/src/cressi_edy.c @@ -389,9 +389,8 @@ cressi_edy_device_dump (dc_device_t *abstract, dc_buffer_t *buffer) { cressi_edy_device_t *device = (cressi_edy_device_t *) abstract; - // Erase the current contents of the buffer and - // allocate the required amount of memory. - if (!dc_buffer_clear (buffer) || !dc_buffer_resize (buffer, device->layout->memsize)) { + // Allocate the required amount of memory. + if (!dc_buffer_resize (buffer, device->layout->memsize)) { ERROR (abstract->context, "Insufficient buffer space available."); return DC_STATUS_NOMEMORY; } diff --git a/src/cressi_leonardo.c b/src/cressi_leonardo.c index 4021288..e9d142b 100644 --- a/src/cressi_leonardo.c +++ b/src/cressi_leonardo.c @@ -320,9 +320,8 @@ cressi_leonardo_device_dump (dc_device_t *abstract, dc_buffer_t *buffer) dc_status_t status = DC_STATUS_SUCCESS; cressi_leonardo_device_t *device = (cressi_leonardo_device_t *) abstract; - // Erase the current contents of the buffer and - // pre-allocate the required amount of memory. - if (!dc_buffer_clear (buffer) || !dc_buffer_resize (buffer, SZ_MEMORY)) { + // Allocate the required amount of memory. + if (!dc_buffer_resize (buffer, SZ_MEMORY)) { ERROR (abstract->context, "Insufficient buffer space available."); return DC_STATUS_NOMEMORY; } diff --git a/src/device.c b/src/device.c index aba42d5..7c3da19 100644 --- a/src/device.c +++ b/src/device.c @@ -316,6 +316,11 @@ dc_device_dump (dc_device_t *device, dc_buffer_t *buffer) if (device->vtable->dump == NULL) return DC_STATUS_UNSUPPORTED; + if (buffer == NULL) + return DC_STATUS_INVALIDARGS; + + dc_buffer_clear (buffer); + return device->vtable->dump (device, buffer); } diff --git a/src/diverite_nitekq.c b/src/diverite_nitekq.c index 8524b56..6fc38b5 100644 --- a/src/diverite_nitekq.c +++ b/src/diverite_nitekq.c @@ -258,8 +258,8 @@ diverite_nitekq_device_dump (dc_device_t *abstract, dc_buffer_t *buffer) dc_status_t rc = DC_STATUS_SUCCESS; unsigned char packet[256] = {0}; - // Erase the current contents of the buffer. - if (!dc_buffer_clear (buffer) || !dc_buffer_reserve (buffer, SZ_PACKET + SZ_MEMORY)) { + // Pre-allocate the required amount of memory. + if (!dc_buffer_reserve (buffer, SZ_PACKET + SZ_MEMORY)) { ERROR (abstract->context, "Insufficient buffer space available."); return DC_STATUS_NOMEMORY; } diff --git a/src/hw_ostc.c b/src/hw_ostc.c index 8967393..941b3ef 100644 --- a/src/hw_ostc.c +++ b/src/hw_ostc.c @@ -219,12 +219,6 @@ hw_ostc_device_dump (dc_device_t *abstract, dc_buffer_t *buffer) dc_status_t status = DC_STATUS_SUCCESS; hw_ostc_device_t *device = (hw_ostc_device_t*) abstract; - // Erase the current contents of the buffer. - if (!dc_buffer_clear (buffer)) { - ERROR (abstract->context, "Insufficient buffer space available."); - return DC_STATUS_NOMEMORY; - } - // Enable progress notifications. dc_event_progress_t progress = EVENT_PROGRESS_INITIALIZER; progress.maximum = SZ_HEADER + SZ_FW_NEW; diff --git a/src/hw_ostc3.c b/src/hw_ostc3.c index e240342..0391c53 100644 --- a/src/hw_ostc3.c +++ b/src/hw_ostc3.c @@ -1555,12 +1555,6 @@ hw_ostc3_device_dump (dc_device_t *abstract, dc_buffer_t *buffer) { hw_ostc3_device_t *device = (hw_ostc3_device_t *) abstract; - // Erase the current contents of the buffer. - if (!dc_buffer_clear (buffer)) { - ERROR (abstract->context, "Insufficient buffer space available."); - return DC_STATUS_NOMEMORY; - } - // Enable progress notifications. dc_event_progress_t progress = EVENT_PROGRESS_INITIALIZER; progress.maximum = SZ_MEMORY; diff --git a/src/mares_darwin.c b/src/mares_darwin.c index e4d118f..0d5152d 100644 --- a/src/mares_darwin.c +++ b/src/mares_darwin.c @@ -219,9 +219,8 @@ mares_darwin_device_dump (dc_device_t *abstract, dc_buffer_t *buffer) assert (device->layout != NULL); - // Erase the current contents of the buffer and - // allocate the required amount of memory. - if (!dc_buffer_clear (buffer) || !dc_buffer_resize (buffer, device->layout->memsize)) { + // Allocate the required amount of memory. + if (!dc_buffer_resize (buffer, device->layout->memsize)) { ERROR (abstract->context, "Insufficient buffer space available."); return DC_STATUS_NOMEMORY; } diff --git a/src/mares_iconhd.c b/src/mares_iconhd.c index bccc570..c9352e2 100644 --- a/src/mares_iconhd.c +++ b/src/mares_iconhd.c @@ -403,9 +403,8 @@ mares_iconhd_device_dump (dc_device_t *abstract, dc_buffer_t *buffer) { mares_iconhd_device_t *device = (mares_iconhd_device_t *) abstract; - // Erase the current contents of the buffer and - // pre-allocate the required amount of memory. - if (!dc_buffer_clear (buffer) || !dc_buffer_resize (buffer, device->layout->memsize)) { + // Allocate the required amount of memory. + if (!dc_buffer_resize (buffer, device->layout->memsize)) { ERROR (abstract->context, "Insufficient buffer space available."); return DC_STATUS_NOMEMORY; } diff --git a/src/mares_nemo.c b/src/mares_nemo.c index d6d4e01..a83b459 100644 --- a/src/mares_nemo.c +++ b/src/mares_nemo.c @@ -193,9 +193,8 @@ mares_nemo_device_dump (dc_device_t *abstract, dc_buffer_t *buffer) dc_status_t status = DC_STATUS_SUCCESS; mares_nemo_device_t *device = (mares_nemo_device_t *) abstract; - // Erase the current contents of the buffer and - // pre-allocate the required amount of memory. - if (!dc_buffer_clear (buffer) || !dc_buffer_reserve (buffer, MEMORYSIZE)) { + // Pre-allocate the required amount of memory. + if (!dc_buffer_reserve (buffer, MEMORYSIZE)) { ERROR (abstract->context, "Insufficient buffer space available."); return DC_STATUS_NOMEMORY; } diff --git a/src/mares_puck.c b/src/mares_puck.c index 5006b43..6d921f0 100644 --- a/src/mares_puck.c +++ b/src/mares_puck.c @@ -224,9 +224,8 @@ mares_puck_device_dump (dc_device_t *abstract, dc_buffer_t *buffer) assert (device->layout != NULL); - // Erase the current contents of the buffer and - // allocate the required amount of memory. - if (!dc_buffer_clear (buffer) || !dc_buffer_resize (buffer, device->layout->memsize)) { + // Allocate the required amount of memory. + if (!dc_buffer_resize (buffer, device->layout->memsize)) { ERROR (abstract->context, "Insufficient buffer space available."); return DC_STATUS_NOMEMORY; } diff --git a/src/oceanic_common.c b/src/oceanic_common.c index 43bc06d..1ab491d 100644 --- a/src/oceanic_common.c +++ b/src/oceanic_common.c @@ -156,9 +156,8 @@ oceanic_common_device_dump (dc_device_t *abstract, dc_buffer_t *buffer) assert (device != NULL); assert (device->layout != NULL); - // Erase the current contents of the buffer and - // allocate the required amount of memory. - if (!dc_buffer_clear (buffer) || !dc_buffer_resize (buffer, device->layout->memsize)) { + // Allocate the required amount of memory. + if (!dc_buffer_resize (buffer, device->layout->memsize)) { ERROR (abstract->context, "Insufficient buffer space available."); return DC_STATUS_NOMEMORY; } diff --git a/src/reefnet_sensus.c b/src/reefnet_sensus.c index 0fc6e52..b8d0820 100644 --- a/src/reefnet_sensus.c +++ b/src/reefnet_sensus.c @@ -279,9 +279,8 @@ reefnet_sensus_device_dump (dc_device_t *abstract, dc_buffer_t *buffer) dc_status_t status = DC_STATUS_SUCCESS; reefnet_sensus_device_t *device = (reefnet_sensus_device_t*) abstract; - // Erase the current contents of the buffer and - // pre-allocate the required amount of memory. - if (!dc_buffer_clear (buffer) || !dc_buffer_reserve (buffer, SZ_MEMORY)) { + // Pre-allocate the required amount of memory. + if (!dc_buffer_reserve (buffer, SZ_MEMORY)) { ERROR (abstract->context, "Insufficient buffer space available."); return DC_STATUS_NOMEMORY; } diff --git a/src/reefnet_sensuspro.c b/src/reefnet_sensuspro.c index 5af9181..0001f1c 100644 --- a/src/reefnet_sensuspro.c +++ b/src/reefnet_sensuspro.c @@ -271,9 +271,8 @@ reefnet_sensuspro_device_dump (dc_device_t *abstract, dc_buffer_t *buffer) dc_status_t status = DC_STATUS_SUCCESS; reefnet_sensuspro_device_t *device = (reefnet_sensuspro_device_t*) abstract; - // Erase the current contents of the buffer and - // pre-allocate the required amount of memory. - if (!dc_buffer_clear (buffer) || !dc_buffer_reserve (buffer, SZ_MEMORY)) { + // Pre-allocate the required amount of memory. + if (!dc_buffer_reserve (buffer, SZ_MEMORY)) { ERROR (abstract->context, "Insufficient buffer space available."); return DC_STATUS_NOMEMORY; } diff --git a/src/reefnet_sensusultra.c b/src/reefnet_sensusultra.c index a6aef5a..9ac95a2 100644 --- a/src/reefnet_sensusultra.c +++ b/src/reefnet_sensusultra.c @@ -379,9 +379,8 @@ reefnet_sensusultra_device_dump (dc_device_t *abstract, dc_buffer_t *buffer) { reefnet_sensusultra_device_t *device = (reefnet_sensusultra_device_t*) abstract; - // Erase the current contents of the buffer and - // pre-allocate the required amount of memory. - if (!dc_buffer_clear (buffer) || !dc_buffer_reserve (buffer, SZ_MEMORY)) { + // Pre-allocate the required amount of memory. + if (!dc_buffer_reserve (buffer, SZ_MEMORY)) { ERROR (abstract->context, "Insufficient buffer space available."); return DC_STATUS_NOMEMORY; } diff --git a/src/shearwater_predator.c b/src/shearwater_predator.c index a47d414..6326785 100644 --- a/src/shearwater_predator.c +++ b/src/shearwater_predator.c @@ -127,8 +127,8 @@ shearwater_predator_device_dump (dc_device_t *abstract, dc_buffer_t *buffer) { shearwater_common_device_t *device = (shearwater_common_device_t *) abstract; - // Erase the current contents of the buffer. - if (!dc_buffer_clear (buffer) || !dc_buffer_reserve (buffer, SZ_MEMORY)) { + // Pre-allocate the required amount of memory. + if (!dc_buffer_reserve (buffer, SZ_MEMORY)) { ERROR (abstract->context, "Insufficient buffer space available."); return DC_STATUS_NOMEMORY; } diff --git a/src/suunto_eon.c b/src/suunto_eon.c index f41fae6..8b9138c 100644 --- a/src/suunto_eon.c +++ b/src/suunto_eon.c @@ -149,9 +149,8 @@ suunto_eon_device_dump (dc_device_t *abstract, dc_buffer_t *buffer) dc_status_t status = DC_STATUS_SUCCESS; suunto_eon_device_t *device = (suunto_eon_device_t*) abstract; - // Erase the current contents of the buffer and - // pre-allocate the required amount of memory. - if (!dc_buffer_clear (buffer) || !dc_buffer_reserve (buffer, SZ_MEMORY)) { + // Pre-allocate the required amount of memory. + if (!dc_buffer_reserve (buffer, SZ_MEMORY)) { ERROR (abstract->context, "Insufficient buffer space available."); return DC_STATUS_NOMEMORY; } diff --git a/src/suunto_solution.c b/src/suunto_solution.c index ffa8262..9480252 100644 --- a/src/suunto_solution.c +++ b/src/suunto_solution.c @@ -143,9 +143,8 @@ suunto_solution_device_dump (dc_device_t *abstract, dc_buffer_t *buffer) dc_status_t status = DC_STATUS_SUCCESS; suunto_solution_device_t *device = (suunto_solution_device_t*) abstract; - // Erase the current contents of the buffer and - // allocate the required amount of memory. - if (!dc_buffer_clear (buffer) || !dc_buffer_resize (buffer, SZ_MEMORY)) { + // Allocate the required amount of memory. + if (!dc_buffer_resize (buffer, SZ_MEMORY)) { ERROR (abstract->context, "Insufficient buffer space available."); return DC_STATUS_NOMEMORY; } diff --git a/src/suunto_vyper.c b/src/suunto_vyper.c index 89be1fc..276e633 100644 --- a/src/suunto_vyper.c +++ b/src/suunto_vyper.c @@ -454,9 +454,8 @@ suunto_vyper_read_dive (dc_device_t *abstract, dc_buffer_t *buffer, int init, dc static dc_status_t suunto_vyper_device_dump (dc_device_t *abstract, dc_buffer_t *buffer) { - // Erase the current contents of the buffer and - // allocate the required amount of memory. - if (!dc_buffer_clear (buffer) || !dc_buffer_resize (buffer, SZ_MEMORY)) { + // Allocate the required amount of memory. + if (!dc_buffer_resize (buffer, SZ_MEMORY)) { ERROR (abstract->context, "Insufficient buffer space available."); return DC_STATUS_NOMEMORY; } diff --git a/src/uwatec_aladin.c b/src/uwatec_aladin.c index dc697c2..0f1a49a 100644 --- a/src/uwatec_aladin.c +++ b/src/uwatec_aladin.c @@ -178,9 +178,8 @@ uwatec_aladin_device_dump (dc_device_t *abstract, dc_buffer_t *buffer) dc_status_t status = DC_STATUS_SUCCESS; uwatec_aladin_device_t *device = (uwatec_aladin_device_t*) abstract; - // Erase the current contents of the buffer and - // pre-allocate the required amount of memory. - if (!dc_buffer_clear (buffer) || !dc_buffer_reserve (buffer, SZ_MEMORY)) { + // Pre-allocate the required amount of memory. + if (!dc_buffer_reserve (buffer, SZ_MEMORY)) { ERROR (abstract->context, "Insufficient buffer space available."); return DC_STATUS_NOMEMORY; } diff --git a/src/uwatec_g2.c b/src/uwatec_g2.c index 5031055..fc24b71 100644 --- a/src/uwatec_g2.c +++ b/src/uwatec_g2.c @@ -275,12 +275,6 @@ uwatec_g2_device_dump (dc_device_t *abstract, dc_buffer_t *buffer) uwatec_g2_device_t *device = (uwatec_g2_device_t*) abstract; dc_status_t rc = DC_STATUS_SUCCESS; - // Erase the current contents of the buffer. - if (!dc_buffer_clear (buffer)) { - ERROR (abstract->context, "Insufficient buffer space available."); - return DC_STATUS_NOMEMORY; - } - // Enable progress notifications. dc_event_progress_t progress = EVENT_PROGRESS_INITIALIZER; device_event_emit (&device->base, DC_EVENT_PROGRESS, &progress); diff --git a/src/uwatec_memomouse.c b/src/uwatec_memomouse.c index 90466a0..ca3a747 100644 --- a/src/uwatec_memomouse.c +++ b/src/uwatec_memomouse.c @@ -450,12 +450,6 @@ uwatec_memomouse_device_dump (dc_device_t *abstract, dc_buffer_t *buffer) uwatec_memomouse_device_t *device = (uwatec_memomouse_device_t*) abstract; dc_status_t rc = DC_STATUS_SUCCESS; - // Erase the current contents of the buffer. - if (!dc_buffer_clear (buffer)) { - ERROR (abstract->context, "Insufficient buffer space available."); - return DC_STATUS_NOMEMORY; - } - // Give the interface some time to notice the DTR // line change from a previous transfer (if any). dc_iostream_sleep (device->iostream, 500); diff --git a/src/uwatec_meridian.c b/src/uwatec_meridian.c index 5844c29..17f1b62 100644 --- a/src/uwatec_meridian.c +++ b/src/uwatec_meridian.c @@ -288,12 +288,6 @@ uwatec_meridian_device_dump (dc_device_t *abstract, dc_buffer_t *buffer) uwatec_meridian_device_t *device = (uwatec_meridian_device_t*) abstract; dc_status_t rc = DC_STATUS_SUCCESS; - // Erase the current contents of the buffer. - if (!dc_buffer_clear (buffer)) { - ERROR (abstract->context, "Insufficient buffer space available."); - return DC_STATUS_NOMEMORY; - } - // Enable progress notifications. dc_event_progress_t progress = EVENT_PROGRESS_INITIALIZER; device_event_emit (&device->base, DC_EVENT_PROGRESS, &progress); diff --git a/src/uwatec_smart.c b/src/uwatec_smart.c index d30bee6..95497c5 100644 --- a/src/uwatec_smart.c +++ b/src/uwatec_smart.c @@ -243,12 +243,6 @@ uwatec_smart_device_dump (dc_device_t *abstract, dc_buffer_t *buffer) uwatec_smart_device_t *device = (uwatec_smart_device_t*) abstract; dc_status_t rc = DC_STATUS_SUCCESS; - // Erase the current contents of the buffer. - if (!dc_buffer_clear (buffer)) { - ERROR (abstract->context, "Insufficient buffer space available."); - return DC_STATUS_NOMEMORY; - } - // Enable progress notifications. dc_event_progress_t progress = EVENT_PROGRESS_INITIALIZER; device_event_emit (&device->base, DC_EVENT_PROGRESS, &progress); diff --git a/src/zeagle_n2ition3.c b/src/zeagle_n2ition3.c index 01b9d5e..58f81ba 100644 --- a/src/zeagle_n2ition3.c +++ b/src/zeagle_n2ition3.c @@ -263,9 +263,8 @@ zeagle_n2ition3_device_read (dc_device_t *abstract, unsigned int address, unsign static dc_status_t zeagle_n2ition3_device_dump (dc_device_t *abstract, dc_buffer_t *buffer) { - // Erase the current contents of the buffer and - // allocate the required amount of memory. - if (!dc_buffer_clear (buffer) || !dc_buffer_resize (buffer, SZ_MEMORY)) { + // Allocate the required amount of memory. + if (!dc_buffer_resize (buffer, SZ_MEMORY)) { ERROR (abstract->context, "Insufficient buffer space available."); return DC_STATUS_NOMEMORY; }