[PATCH 09/14] Cleanup: dc_buffer_clear() should be a void function

Dirk Hohndel dirk at hohndel.org
Wed Jan 3 11:35:12 PST 2018


We sometimes ignored its return value, sometimes we didn't.
Semantically, clearing a non-existing buffer is just a noop.

Careful - one side effect of the old semantic was that dc_buffer_clear()
plus a bail on failure could be used to test if the buffer had been
allocated. Right now there is at least one call site where we later call
dc_buffer_apend() without checking its return value. This will be fixed
in a later commit in this series.

Coverity CID 207756
Coverity CID 207714
Coverity CID 207800
Coverity CID 207729

Signed-off-by: Dirk Hohndel <dirk at hohndel.org>
---
 include/libdivecomputer/buffer.h |  2 +-
 src/atomics_cobalt.c             |  5 +----
 src/buffer.c                     | 16 ++++++++--------
 src/citizen_aqualand.c           |  8 ++------
 src/cochran_commander.c          |  7 ++-----
 src/cressi_edy.c                 |  3 ++-
 src/cressi_leonardo.c            |  3 ++-
 src/diverite_nitekq.c            |  3 ++-
 src/hw_ostc.c                    | 10 ++--------
 src/hw_ostc3.c                   |  5 +----
 src/mares_darwin.c               |  3 ++-
 src/mares_iconhd.c               |  3 ++-
 src/mares_nemo.c                 |  3 ++-
 src/mares_puck.c                 |  3 ++-
 src/oceanic_common.c             |  6 +++---
 src/oceanic_vtpro.c              |  3 +--
 src/reefnet_sensus.c             |  3 ++-
 src/reefnet_sensuspro.c          |  3 ++-
 src/reefnet_sensusultra.c        |  3 ++-
 src/scubapro_g2.c                |  5 +----
 src/shearwater_common.c          | 10 ++--------
 src/shearwater_predator.c        |  3 ++-
 src/suunto_common2.c             |  3 ++-
 src/suunto_eon.c                 |  3 ++-
 src/suunto_solution.c            |  3 ++-
 src/suunto_vyper.c               |  8 +++-----
 src/uwatec_aladin.c              |  3 ++-
 src/uwatec_memomouse.c           | 10 ++--------
 src/uwatec_meridian.c            |  5 +----
 src/uwatec_smart.c               |  5 +----
 src/zeagle_n2ition3.c            |  3 ++-
 31 files changed, 63 insertions(+), 90 deletions(-)

diff --git a/include/libdivecomputer/buffer.h b/include/libdivecomputer/buffer.h
index 2af4822ad8b5..a807187d48d1 100644
--- a/include/libdivecomputer/buffer.h
+++ b/include/libdivecomputer/buffer.h
@@ -36,7 +36,7 @@ dc_buffer_new (size_t capacity);
 void
 dc_buffer_free (dc_buffer_t *buffer);
 
-int
+void
 dc_buffer_clear (dc_buffer_t *buffer);
 
 int
diff --git a/src/atomics_cobalt.c b/src/atomics_cobalt.c
index 7c7dccb04876..a5ce98c9a302 100644
--- a/src/atomics_cobalt.c
+++ b/src/atomics_cobalt.c
@@ -258,10 +258,7 @@ atomics_cobalt_read_dive (dc_device_t *abstract, dc_buffer_t *buffer, int init,
 		return DC_STATUS_CANCELLED;
 
 	// Erase the current contents of the buffer.
-	if (!dc_buffer_clear (buffer)) {
-		ERROR (abstract->context, "Insufficient buffer space available.");
-		return DC_STATUS_NOMEMORY;
-	}
+	dc_buffer_clear (buffer);
 
 	// Send the command to the dive computer.
 	uint8_t bRequest = 0;
diff --git a/src/buffer.c b/src/buffer.c
index 5b203fb261d9..10d84ab67fb6 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -67,19 +67,17 @@ dc_buffer_free (dc_buffer_t *buffer)
 }
 
 
-int
+void
 dc_buffer_clear (dc_buffer_t *buffer)
 {
-	if (buffer == NULL)
-		return 0;
-
-	buffer->offset = 0;
-	buffer->size = 0;
-
-	return 1;
+	if (buffer != NULL) {
+		buffer->offset = 0;
+		buffer->size = 0;
+	}
 }
 
 
+// static, internal function; only called with buffer != NULL
 static size_t
 dc_buffer_expand_calc (dc_buffer_t *buffer, size_t n)
 {
@@ -92,6 +90,7 @@ dc_buffer_expand_calc (dc_buffer_t *buffer, size_t n)
 }
 
 
+// static, internal function; only called with buffer != NULL
 static int
 dc_buffer_expand_append (dc_buffer_t *buffer, size_t n)
 {
@@ -123,6 +122,7 @@ dc_buffer_expand_append (dc_buffer_t *buffer, size_t n)
 }
 
 
+// static, internal function; only called with buffer != NULL
 static int
 dc_buffer_expand_prepend (dc_buffer_t *buffer, size_t n)
 {
diff --git a/src/citizen_aqualand.c b/src/citizen_aqualand.c
index 3af5d528e863..cfcdbb85ee81 100644
--- a/src/citizen_aqualand.c
+++ b/src/citizen_aqualand.c
@@ -152,12 +152,8 @@ 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;
-	}
+	// Erase the current contents of the buffer
+	dc_buffer_clear (buffer);
 
 	dc_iostream_set_dtr (device->iostream, 1);
 
diff --git a/src/cochran_commander.c b/src/cochran_commander.c
index e21ec7e3f0bc..1225c3808ac8 100644
--- a/src/cochran_commander.c
+++ b/src/cochran_commander.c
@@ -842,11 +842,8 @@ 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;
-	}
+	// Erase the buffer content
+	dc_buffer_clear(buffer);
 
 	// Reserve space
 	if (!dc_buffer_resize(buffer, size)) {
diff --git a/src/cressi_edy.c b/src/cressi_edy.c
index 80e4fac4d854..e5302ace41e4 100644
--- a/src/cressi_edy.c
+++ b/src/cressi_edy.c
@@ -391,7 +391,8 @@ cressi_edy_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, device->layout->memsize)) {
+	dc_buffer_clear (buffer);
+	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 402128821fdd..9ea323b6dddc 100644
--- a/src/cressi_leonardo.c
+++ b/src/cressi_leonardo.c
@@ -322,7 +322,8 @@ cressi_leonardo_device_dump (dc_device_t *abstract, dc_buffer_t *buffer)
 
 	// 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)) {
+	dc_buffer_clear (buffer);
+	if (!dc_buffer_resize (buffer, SZ_MEMORY)) {
 		ERROR (abstract->context, "Insufficient buffer space available.");
 		return DC_STATUS_NOMEMORY;
 	}
diff --git a/src/diverite_nitekq.c b/src/diverite_nitekq.c
index 8524b568315f..9ed1fa7df538 100644
--- a/src/diverite_nitekq.c
+++ b/src/diverite_nitekq.c
@@ -259,7 +259,8 @@ diverite_nitekq_device_dump (dc_device_t *abstract, dc_buffer_t *buffer)
 	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)) {
+	dc_buffer_clear (buffer);
+	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 36d608086e96..4e4335caf291 100644
--- a/src/hw_ostc.c
+++ b/src/hw_ostc.c
@@ -220,10 +220,7 @@ hw_ostc_device_dump (dc_device_t *abstract, dc_buffer_t *buffer)
 	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;
-	}
+	dc_buffer_clear (buffer);
 
 	// Enable progress notifications.
 	dc_event_progress_t progress = EVENT_PROGRESS_INITIALIZER;
@@ -507,10 +504,7 @@ hw_ostc_device_screenshot (dc_device_t *abstract, dc_buffer_t *buffer, hw_ostc_f
 		return DC_STATUS_INVALIDARGS;
 
 	// Erase the current contents of the buffer.
-	if (!dc_buffer_clear (buffer)) {
-		ERROR (abstract->context, "Insufficient buffer space available.");
-		return DC_STATUS_NOMEMORY;
-	}
+	dc_buffer_clear (buffer);
 
 	// Bytes per pixel (RGB formats only).
 	unsigned int bpp = 0;
diff --git a/src/hw_ostc3.c b/src/hw_ostc3.c
index e240342cc2f6..eca8dfbc30e8 100644
--- a/src/hw_ostc3.c
+++ b/src/hw_ostc3.c
@@ -1556,10 +1556,7 @@ 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;
-	}
+	dc_buffer_clear (buffer);
 
 	// Enable progress notifications.
 	dc_event_progress_t progress = EVENT_PROGRESS_INITIALIZER;
diff --git a/src/mares_darwin.c b/src/mares_darwin.c
index 4f87f6fcd14a..308477cda6b6 100644
--- a/src/mares_darwin.c
+++ b/src/mares_darwin.c
@@ -221,7 +221,8 @@ mares_darwin_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, device->layout->memsize)) {
+	dc_buffer_clear (buffer);
+	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 990f46657bdb..b56da27a5b8a 100644
--- a/src/mares_iconhd.c
+++ b/src/mares_iconhd.c
@@ -399,7 +399,8 @@ mares_iconhd_device_dump (dc_device_t *abstract, dc_buffer_t *buffer)
 
 	// 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)) {
+	dc_buffer_clear (buffer);
+	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 d6d4e015db63..b3d262a5c18c 100644
--- a/src/mares_nemo.c
+++ b/src/mares_nemo.c
@@ -195,7 +195,8 @@ mares_nemo_device_dump (dc_device_t *abstract, dc_buffer_t *buffer)
 
 	// 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)) {
+	dc_buffer_clear (buffer);
+	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 5006b43ef0b9..23f4d9e794c2 100644
--- a/src/mares_puck.c
+++ b/src/mares_puck.c
@@ -226,7 +226,8 @@ mares_puck_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, device->layout->memsize)) {
+	dc_buffer_clear (buffer);
+	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 43bc06ddd0db..7f67418794b6 100644
--- a/src/oceanic_common.c
+++ b/src/oceanic_common.c
@@ -158,7 +158,8 @@ oceanic_common_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, device->layout->memsize)) {
+	dc_buffer_clear (buffer);
+	if (!dc_buffer_resize (buffer, device->layout->memsize)) {
 		ERROR (abstract->context, "Insufficient buffer space available.");
 		return DC_STATUS_NOMEMORY;
 	}
@@ -188,8 +189,7 @@ oceanic_common_device_logbook (dc_device_t *abstract, dc_event_progress_t *progr
 	const oceanic_common_layout_t *layout = device->layout;
 
 	// Erase the buffer.
-	if (!dc_buffer_clear (logbook))
-		return DC_STATUS_NOMEMORY;
+	dc_buffer_clear (logbook);
 
 	// For devices without a logbook ringbuffer, downloading dives isn't
 	// possible. This is not considered a fatal error, but handled as if there
diff --git a/src/oceanic_vtpro.c b/src/oceanic_vtpro.c
index e1ba31ced88a..ca3a2fc2a479 100644
--- a/src/oceanic_vtpro.c
+++ b/src/oceanic_vtpro.c
@@ -299,8 +299,7 @@ oceanic_aeris500ai_device_logbook (dc_device_t *abstract, dc_event_progress_t *p
 	const oceanic_common_layout_t *layout = device->base.layout;
 
 	// Erase the buffer.
-	if (!dc_buffer_clear (logbook))
-		return DC_STATUS_NOMEMORY;
+	dc_buffer_clear (logbook);
 
 	// Read the pointer data.
 	unsigned char pointers[PAGESIZE] = {0};
diff --git a/src/reefnet_sensus.c b/src/reefnet_sensus.c
index 0fc6e5228cc2..29b9bb1c8429 100644
--- a/src/reefnet_sensus.c
+++ b/src/reefnet_sensus.c
@@ -281,7 +281,8 @@ reefnet_sensus_device_dump (dc_device_t *abstract, dc_buffer_t *buffer)
 
 	// 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)) {
+	dc_buffer_clear (buffer);
+	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 e50cb44937f1..b6bdd6bfe751 100644
--- a/src/reefnet_sensuspro.c
+++ b/src/reefnet_sensuspro.c
@@ -265,7 +265,8 @@ reefnet_sensuspro_device_dump (dc_device_t *abstract, dc_buffer_t *buffer)
 
 	// 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)) {
+	dc_buffer_clear (buffer);
+	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 a6aef5aca4db..d2c73817efd7 100644
--- a/src/reefnet_sensusultra.c
+++ b/src/reefnet_sensusultra.c
@@ -381,7 +381,8 @@ reefnet_sensusultra_device_dump (dc_device_t *abstract, dc_buffer_t *buffer)
 
 	// 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)) {
+	dc_buffer_clear (buffer);
+	if (!dc_buffer_reserve (buffer, SZ_MEMORY)) {
 		ERROR (abstract->context, "Insufficient buffer space available.");
 		return DC_STATUS_NOMEMORY;
 	}
diff --git a/src/scubapro_g2.c b/src/scubapro_g2.c
index c6c533fbe05e..977932d3933c 100644
--- a/src/scubapro_g2.c
+++ b/src/scubapro_g2.c
@@ -308,10 +308,7 @@ scubapro_g2_device_dump (dc_device_t *abstract, dc_buffer_t *buffer)
 	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;
-	}
+	dc_buffer_clear (buffer);
 
 	// Enable progress notifications.
 	dc_event_progress_t progress = EVENT_PROGRESS_INITIALIZER;
diff --git a/src/shearwater_common.c b/src/shearwater_common.c
index bad14c8ba5d8..f5004552b68a 100644
--- a/src/shearwater_common.c
+++ b/src/shearwater_common.c
@@ -365,10 +365,7 @@ shearwater_common_download (shearwater_common_device_t *device, dc_buffer_t *buf
 	unsigned char response[SZ_PACKET];
 
 	// Erase the current contents of the buffer.
-	if (!dc_buffer_clear (buffer)) {
-		ERROR (abstract->context, "Insufficient buffer space available.");
-		return DC_STATUS_NOMEMORY;
-	}
+	dc_buffer_clear (buffer);
 
 	// Enable progress notifications.
 	unsigned int initial = 0, current = 0, maximum = 3 + size + 1;
@@ -480,10 +477,7 @@ shearwater_common_identifier (shearwater_common_device_t *device, dc_buffer_t *b
 	dc_status_t rc = DC_STATUS_SUCCESS;
 
 	// Erase the buffer.
-	if (!dc_buffer_clear (buffer)) {
-		ERROR (abstract->context, "Insufficient buffer space available.");
-		return DC_STATUS_NOMEMORY;
-	}
+	dc_buffer_clear (buffer);
 
 	// Transfer the request.
 	unsigned int n = 0;
diff --git a/src/shearwater_predator.c b/src/shearwater_predator.c
index a47d4141de9a..6d1214f4abb2 100644
--- a/src/shearwater_predator.c
+++ b/src/shearwater_predator.c
@@ -128,7 +128,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)) {
+	dc_buffer_clear (buffer);
+	if (!dc_buffer_reserve (buffer, SZ_MEMORY)) {
 		ERROR (abstract->context, "Insufficient buffer space available.");
 		return DC_STATUS_NOMEMORY;
 	}
diff --git a/src/suunto_common2.c b/src/suunto_common2.c
index 4aa1699ef8f1..40d32d22e9b5 100644
--- a/src/suunto_common2.c
+++ b/src/suunto_common2.c
@@ -207,7 +207,8 @@ suunto_common2_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, device->layout->memsize)) {
+	dc_buffer_clear (buffer);
+	if (!dc_buffer_resize (buffer, device->layout->memsize)) {
 		ERROR (abstract->context, "Insufficient buffer space available.");
 		return DC_STATUS_NOMEMORY;
 	}
diff --git a/src/suunto_eon.c b/src/suunto_eon.c
index f41fae6e783c..1fbcaa11c74b 100644
--- a/src/suunto_eon.c
+++ b/src/suunto_eon.c
@@ -151,7 +151,8 @@ suunto_eon_device_dump (dc_device_t *abstract, dc_buffer_t *buffer)
 
 	// 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)) {
+	dc_buffer_clear (buffer);
+	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 2e9e14efa707..bbeaf8e90132 100644
--- a/src/suunto_solution.c
+++ b/src/suunto_solution.c
@@ -145,7 +145,8 @@ suunto_solution_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)) {
+	dc_buffer_clear (buffer);
+	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 ba5ad20047b7..cc4680bd7dbe 100644
--- a/src/suunto_vyper.c
+++ b/src/suunto_vyper.c
@@ -333,10 +333,7 @@ suunto_vyper_read_dive (dc_device_t *abstract, dc_buffer_t *buffer, int init, dc
 		return DC_STATUS_CANCELLED;
 
 	// Erase the current contents of the buffer.
-	if (!dc_buffer_clear (buffer)) {
-		ERROR (abstract->context, "Insufficient buffer space available.");
-		return DC_STATUS_NOMEMORY;
-	}
+	dc_buffer_clear (buffer);
 
 	// Send the command to the dive computer.
 	unsigned char command[3] = {init ? 0x08 : 0x09, 0xA5, 0x00};
@@ -448,7 +445,8 @@ 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)) {
+	dc_buffer_clear (buffer);
+	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 dc697c29cc44..8fcd918bfcf8 100644
--- a/src/uwatec_aladin.c
+++ b/src/uwatec_aladin.c
@@ -180,7 +180,8 @@ uwatec_aladin_device_dump (dc_device_t *abstract, dc_buffer_t *buffer)
 
 	// 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)) {
+	dc_buffer_clear (buffer);
+	if (!dc_buffer_reserve (buffer, SZ_MEMORY)) {
 		ERROR (abstract->context, "Insufficient buffer space available.");
 		return DC_STATUS_NOMEMORY;
 	}
diff --git a/src/uwatec_memomouse.c b/src/uwatec_memomouse.c
index 90466a0ef931..e1bd94978a68 100644
--- a/src/uwatec_memomouse.c
+++ b/src/uwatec_memomouse.c
@@ -256,10 +256,7 @@ uwatec_memomouse_read_packet_inner (uwatec_memomouse_device_t *device, dc_buffer
 	dc_device_t *abstract = (dc_device_t *) device;
 
 	// Erase the current contents of the buffer.
-	if (!dc_buffer_clear (buffer)) {
-		ERROR (abstract->context, "Insufficient buffer space available.");
-		return DC_STATUS_NOMEMORY;
-	}
+	dc_buffer_clear (buffer);
 
 	unsigned int nbytes = 0;
 	unsigned int total = PACKETSIZE;
@@ -451,10 +448,7 @@ uwatec_memomouse_device_dump (dc_device_t *abstract, dc_buffer_t *buffer)
 	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;
-	}
+	dc_buffer_clear (buffer);
 
 	// Give the interface some time to notice the DTR
 	// line change from a previous transfer (if any).
diff --git a/src/uwatec_meridian.c b/src/uwatec_meridian.c
index 5844c29e4a98..28e807dbdef4 100644
--- a/src/uwatec_meridian.c
+++ b/src/uwatec_meridian.c
@@ -289,10 +289,7 @@ uwatec_meridian_device_dump (dc_device_t *abstract, dc_buffer_t *buffer)
 	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;
-	}
+	dc_buffer_clear (buffer);
 
 	// Enable progress notifications.
 	dc_event_progress_t progress = EVENT_PROGRESS_INITIALIZER;
diff --git a/src/uwatec_smart.c b/src/uwatec_smart.c
index d30bee6f3f0f..80d5b0285a8d 100644
--- a/src/uwatec_smart.c
+++ b/src/uwatec_smart.c
@@ -244,10 +244,7 @@ uwatec_smart_device_dump (dc_device_t *abstract, dc_buffer_t *buffer)
 	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;
-	}
+	dc_buffer_clear (buffer);
 
 	// Enable progress notifications.
 	dc_event_progress_t progress = EVENT_PROGRESS_INITIALIZER;
diff --git a/src/zeagle_n2ition3.c b/src/zeagle_n2ition3.c
index 01b9d5eccc34..1717ea4e9d6f 100644
--- a/src/zeagle_n2ition3.c
+++ b/src/zeagle_n2ition3.c
@@ -265,7 +265,8 @@ 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)) {
+	dc_buffer_clear (buffer);
+	if (!dc_buffer_resize (buffer, SZ_MEMORY)) {
 		ERROR (abstract->context, "Insufficient buffer space available.");
 		return DC_STATUS_NOMEMORY;
 	}
-- 
2.15.1



More information about the devel mailing list