[SLOF] [PATCH slof] sloffs: Fix -Wunused-result gcc warnings in read/write

Segher Boessenkool segher at kernel.crashing.org
Fri Nov 8 21:14:05 AEDT 2019


Hi Alexey!

On Fri, Nov 08, 2019 at 07:35:28PM +1100, Alexey Kardashevskiy wrote:
> This fixes these:
> 
> sloffs.c:466:2: warning: ignoring return value of ‘read’, declared with attribute warn_unused_result [-Wunused-result]
>   read(fd, data, header_len);
>   ^~~~~~~~~~~~~~~~~~~~~~~~~~

> +	size_t rc;

> +	rc = read(fd, header, sizeof(struct stH));

read returns an ssize_t, not a size_t.  Your code should still work, but
an ssize_t here is more future-proof.

> +	if (rc != sizeof(struct stH)) {
> +		printf("Reading header, rc %ld, errno %d\n", rc, errno);

That should be %zd instead?

> +		free(header);

Should it free(sloffs->name) here as well?

> +		return NULL;
> +	}
>  	free(sloffs->name);
> +
>  	return header;
>  }

(Similar comments for the rest of the file).

HTH,


Segher


More information about the SLOF mailing list