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 #include +#include #include #include #include @@ -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 */