[PATCH 09/14] Cleanup: be explicit about ignoring the return value of dc_buffer_clear

Dirk Hohndel dirk at hohndel.org
Wed Jan 3 07:30:32 PST 2018


> On Jan 3, 2018, at 7:27 AM, Jef Driesen <jef at libdivecomputer.org> wrote:
> 
> On 29-12-17 01:35, Dirk Hohndel wrote:
>> --- a/src/atomics_cobalt.c
>> +++ b/src/atomics_cobalt.c
>> @@ -323,7 +323,7 @@ atomics_cobalt_read_dive (dc_device_t *abstract, dc_buffer_t *buffer, int init,
>>  	// When only two 0xFF bytes are received, there are no more dives.
>>  	unsigned char *data = dc_buffer_get_data (buffer);
>>  	if (nbytes == 2 && data[0] == 0xFF && data[1] == 0xFF) {
>> -		dc_buffer_clear (buffer);
>> +		(void)dc_buffer_clear (buffer);
>>  		return DC_STATUS_SUCCESS;
>>  	}
> 
> Hmm, I'm not really a fan of this. It adds more visual noise for very little real gain (other than silencing the static analyzer).

This is something that we have struggled with in Subsurface. We have generally decided to go with explicitly marking things as void that aren't used, but especially in this circumstance I agree that this is just ugly and distracting.

> Maybe this function should have returned a void instead.

That had been my initial thought as well. If it is passed a NULL pointer, then clearing the buffer is simply a NOP...

If you would like me to do that, I'm happy to rework the patch to do that instead and update the other callers.

/D



More information about the devel mailing list