diff mbox series

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

Message ID 20201113153746.8616-1-philippe.reynes@softathome.com
State Accepted
Commit cc34f04efd63dfdd31ef2dbfd46c15fb485b2888
Delegated to: Tom Rini
Headers show
Series tools: image-host.c: use random instead of rand | expand

Commit Message

Philippe REYNES Nov. 13, 2020, 3:37 p.m. UTC
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 <philippe.reynes@softathome.com>
---
 tools/image-host.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Simon Glass Nov. 16, 2020, 11:53 p.m. UTC | #1
On Fri, 13 Nov 2020 at 08:38, Philippe Reynes
<philippe.reynes@softathome.com> 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 <philippe.reynes@softathome.com>
> ---
>  tools/image-host.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)

Reviewed-by: Simon Glass <sjg@chromium.org>
Tom Rini Nov. 20, 2020, 1:39 a.m. UTC | #2
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 <philippe.reynes@softathome.com>
> Reviewed-by: Simon Glass <sjg@chromium.org>

Applied to u-boot/master, thanks!
diff mbox series

Patch

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++;
 	}