* [PATCH BlueZ] plugins: Fix compilation error on autopair
@ 2013-05-16 14:00 Anderson Lizardo
2013-05-16 14:07 ` Marcel Holtmann
0 siblings, 1 reply; 3+ messages in thread
From: Anderson Lizardo @ 2013-05-16 14:00 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Anderson Lizardo
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);
return btd_register_adapter_driver(&autopair_driver);
--
1.7.9.5
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH BlueZ] plugins: Fix compilation error on autopair
2013-05-16 14:00 [PATCH BlueZ] plugins: Fix compilation error on autopair Anderson Lizardo
@ 2013-05-16 14:07 ` Marcel Holtmann
2013-05-16 16:19 ` Anderson Lizardo
0 siblings, 1 reply; 3+ messages in thread
From: Marcel Holtmann @ 2013-05-16 14:07 UTC (permalink / raw)
To: Anderson Lizardo; +Cc: linux-bluetooth
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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH BlueZ] plugins: Fix compilation error on autopair
2013-05-16 14:07 ` Marcel Holtmann
@ 2013-05-16 16:19 ` Anderson Lizardo
0 siblings, 0 replies; 3+ messages in thread
From: Anderson Lizardo @ 2013-05-16 16:19 UTC (permalink / raw)
To: Marcel Holtmann; +Cc: linux-bluetooth
Hi Marcel,
On Thu, May 16, 2013 at 10:07 AM, Marcel Holtmann <marcel@holtmann.org> wrote:
>> 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().
I just sent another version that uses open()/read() instead.
Compilation tested only.
Regards,
--
Anderson Lizardo
Instituto Nokia de Tecnologia - INdT
Manaus - Brazil
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2013-05-16 16:19 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-05-16 14:00 [PATCH BlueZ] plugins: Fix compilation error on autopair Anderson Lizardo
2013-05-16 14:07 ` Marcel Holtmann
2013-05-16 16:19 ` Anderson Lizardo
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.