From bd273b9f1364556859aeea598a933fac76741cb8 Mon Sep 17 00:00:00 2001
From: ziggurat29 <dev@ziggurat29.com>
Date: Thu, 24 Mar 2016 11:43:45 -0500
Subject: [PATCH] minor; intialize buffer to well-known patter to make it easy
 to see if it was truly filled with random data

---
 examples/random/random_main.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/examples/random/random_main.c b/examples/random/random_main.c
index ae3c48207..d272a9f8a 100644
--- a/examples/random/random_main.c
+++ b/examples/random/random_main.c
@@ -41,6 +41,7 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 #include <fcntl.h>
 #include <errno.h>
 #include <debug.h>
@@ -94,13 +95,17 @@ int rand_main(int argc, char *argv[])
       nsamples  = atoi(argv[1]);
     }
 
-  /* Clip the numer of samples to the configured buffer size */
+  /* Clip the number of samples to the configured buffer size */
 
   if (nsamples > CONFIG_EXAMPLES_MAXSAMPLES)
     {
       nsamples = CONFIG_EXAMPLES_MAXSAMPLES;
     }
 
+  /* fill buffer to make it super-clear as to what has and has not been written */
+
+  memset(buffer,0xcc,sizeof(buffer));
+
   /* Open /dev/random */
 
   fd = open("/dev/random", O_RDONLY);
@@ -114,6 +119,7 @@ int rand_main(int argc, char *argv[])
   /* Read the requested number of samples */
 
   printf("Reading %d random numbers\n", nsamples);
+  fflush(stdout);
   nread = read(fd, buffer, nsamples * sizeof(uint32_t));
   if (nread < 0)
     {
@@ -122,6 +128,12 @@ int rand_main(int argc, char *argv[])
       (void)close(fd);
       exit(EXIT_FAILURE);
     }
+  if (nread != nsamples * sizeof(uint32_t))
+    {
+      fprintf(stderr, "ERROR: Read from /dev/randon only produced %d bytes\n", nread);
+      (void)close(fd);
+      exit(EXIT_FAILURE);
+    }
 
   /* Dump the sample buffer */
 
-- 
GitLab