[PATCH] tools: image-host.c: use random instead of rand

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

[PATCH] tools: image-host.c: use random instead of rand

Philippe Reynes-3
According to the manpage of rand, it is recommended
to use random instead of rand. This commit updates
the function get_random_data to use random.

Reported-by: Coverity (CID: 312953)
Signed-off-by: Philippe Reynes <[hidden email]>
---
 tools/image-host.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/image-host.c b/tools/image-host.c
index 24079b8a27..e32cc64257 100644
--- a/tools/image-host.c
+++ b/tools/image-host.c
@@ -339,10 +339,10 @@ static int get_random_data(void *data, int size)
  goto out;
  }
 
- srand(date.tv_nsec);
+ srandom(date.tv_nsec);
 
  for (i = 0; i < size; i++) {
- *tmp = rand() & 0xff;
+ *tmp = random() & 0xff;
  tmp++;
  }
 
--
2.17.1

Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] tools: image-host.c: use random instead of rand

Simon Glass-3
On Fri, 13 Nov 2020 at 08:38, Philippe Reynes
<[hidden email]> wrote:

>
> According to the manpage of rand, it is recommended
> to use random instead of rand. This commit updates
> the function get_random_data to use random.
>
> Reported-by: Coverity (CID: 312953)
> Signed-off-by: Philippe Reynes <[hidden email]>
> ---
>  tools/image-host.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)

Reviewed-by: Simon Glass <[hidden email]>
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] tools: image-host.c: use random instead of rand

Tom Rini-4
In reply to this post by Philippe Reynes-3
On Fri, Nov 13, 2020 at 04:37:46PM +0100, Philippe Reynes wrote:

> According to the manpage of rand, it is recommended
> to use random instead of rand. This commit updates
> the function get_random_data to use random.
>
> Reported-by: Coverity (CID: 312953)
> Signed-off-by: Philippe Reynes <[hidden email]>
> Reviewed-by: Simon Glass <[hidden email]>

Applied to u-boot/master, thanks!

--
Tom

signature.asc (673 bytes) Download Attachment