diff options
author | Mattias Andrée <maandree@kth.se> | 2023-06-23 17:53:48 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@kth.se> | 2023-06-23 17:53:48 +0200 |
commit | 20a94987f79144f4d273583048c4fd1d06e39515 (patch) | |
tree | d93e021f7d91a7a0438626e867ee4d9c5f64d2a8 | |
parent | Fix documentation (diff) | |
download | libar2simplified-20a94987f79144f4d273583048c4fd1d06e39515.tar.gz libar2simplified-20a94987f79144f4d273583048c4fd1d06e39515.tar.bz2 libar2simplified-20a94987f79144f4d273583048c4fd1d06e39515.tar.xz |
Whitespace fix + do not call srand unless required
Signed-off-by: Mattias Andrée <maandree@kth.se>
-rw-r--r-- | libar2simplified_decode_r.c | 26 |
1 files 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); } } |