Re: [PATCH BlueZ] plugins: Fix compilation error on autopair

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Anderson,

> Fix this error caught using gcc 4.6.3:
> 
> plugins/autopair.c: In function ‘autopair_init’:
> plugins/autopair.c:154:8: error: ignoring return value of ‘fread’,
> declared with attribute warn_unused_result [-Werror=unused-result]
> ---
> plugins/autopair.c |    8 ++++++--
> 1 file changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/plugins/autopair.c b/plugins/autopair.c
> index 5d90f9d..5afc357 100644
> --- a/plugins/autopair.c
> +++ b/plugins/autopair.c
> @@ -146,15 +146,19 @@ static struct btd_adapter_driver autopair_driver = {
> static int autopair_init(void)
> {
> 	/* Initialize the random seed from /dev/urandom */
> -	unsigned int seed = time(NULL);
> +	unsigned int seed;
> +	size_t nread = 0;
> 	FILE *f;
> 
> 	f = fopen("/dev/urandom", "rb");
> 	if (f != NULL) {
> -		fread(&seed, sizeof(seed), 1, f);
> +		nread = fread(&seed, sizeof(seed), 1, f);
> 		fclose(f);
> 	}
> 
> +	if (f == NULL || nread != 1)
> +		seed = time(NULL);
> +
> 	srand(seed);

lets redo this in actually readable code ;)

Checking f twice is not acceptable. And I still wonder why fopen() is here preferred over open().

Regards

Marcel


--
To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Bluez Devel]     [Linux Wireless Networking]     [Linux Wireless Personal Area Networking]     [Linux ATH6KL]     [Linux USB Devel]     [Linux Media Drivers]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux