From 20a94987f79144f4d273583048c4fd1d06e39515 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Fri, 23 Jun 2023 17:53:48 +0200 Subject: Whitespace fix + do not call srand unless required MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- libar2simplified_decode_r.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/libar2simplified_decode_r.c b/libar2simplified_decode_r.c index e49907c..d5df293 100644 --- a/libar2simplified_decode_r.c +++ b/libar2simplified_decode_r.c @@ -50,22 +50,24 @@ random_salt(char *out, size_t n, int (*random_byte_generator)(char *out, size_t } else { i = 0; #ifdef __linux__ - for(; i < n; i += (size_t)r) { + for (; i < n; i += (size_t)r) { r = getrandom(&out[i], n - i, GRND_NONBLOCK); - if(r < 0) + if (r < 0) break; } #endif - if (!srand_called) { - srand((unsigned int)time(NULL) ^ (unsigned int)rand()); - srand_called = 1; - } - for(; i < n; i++) { - xi = rand(); - x = (double)xi; - x /= (double)RAND_MAX; - x *= 63; - out[i] = (char)x; + if (i < n) { + if (!srand_called) { + srand((unsigned int)time(NULL) ^ (unsigned int)rand()); + srand_called = 1; + } + do { + xi = rand(); + x = (double)xi; + x /= (double)RAND_MAX; + x *= 63; + out[i] = (char)x; + } while (++i < n); } } -- cgit v1.2.3-70-g09d2