[PATCH 10/14] Cleanup: check return value of ioctl()

Jef Driesen jef at libdivecomputer.org
Wed Jan 3 07:58:24 PST 2018


On 2018-01-03 16:39, Dirk Hohndel wrote:
>> On Jan 3, 2018, at 7:31 AM, Jef Driesen <jef at libdivecomputer.org> 
>> wrote:
>> 
>> On 29-12-17 01:35, Dirk Hohndel wrote:
>>> It's checked for all the other invocations...
>>> Coverity CID 207796
>>> Signed-off-by: Dirk Hohndel <dirk at hohndel.org>
>>> ---
>>>  src/serial_posix.c | 6 +++++-
>>>  1 file changed, 5 insertions(+), 1 deletion(-)
>>> diff --git a/src/serial_posix.c b/src/serial_posix.c
>>> index 1698df8159b3..9a9373e32fb9 100644
>>> --- a/src/serial_posix.c
>>> +++ b/src/serial_posix.c
>>> @@ -262,7 +262,11 @@ dc_serial_close (dc_iostream_t *abstract)
>>>    #ifndef ENABLE_PTY
>>>  	// Disable exclusive access mode.
>>> -	ioctl (device->fd, TIOCNXCL, NULL);
>>> +	if (ioctl (device->fd, TIOCNXCL, NULL)) {
>>> +		int errcode = errno;
>>> +		SYSERROR (abstract->context, errcode);
>>> +		dc_status_set_error(&status, syserror (errcode));
>>> +	}
>>>  #endif
>> 
>> I didn't check this one, because it's not the most useful one. But it 
>> also doesn't really hurt, so I'm fine with it either way.
>> 
>> Note that the error code returned by the dc_serial_close() function is 
>> mainly for informative purposes anyway. The caller can't really do 
>> much with it other then reporting it.
> 
> I'm fine either way - we can always mark this as intentional in
> Coverity (btw, you haven't asked for access to the scan reports - can
> you see the reports without me giving you access after all?)

I haven't checked yet, but I certainly will because I'm sure it's useful 
to see what coverity actually reports for all these issues. But I need 
to leave in a few minutes, and wanted to send my comments as soon as 
possible :-)

> I simply added these checks because in general libdivecomputer is
> extremely consistent and conservative with error checking, so this did
> seem like an unintentional omission to me.

It causes no harm, so let's just add the check.

Jef


More information about the devel mailing list