diff options
author | Mattias Andrée <maandree@kth.se> | 2024-09-17 21:59:29 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@kth.se> | 2024-09-17 21:59:29 +0200 |
commit | 31d1ea0664925ff638c4b30c89cc31dcc93e809b (patch) | |
tree | 678c9303f6ebd1fe39aa0df4d607bf689ff9a878 | |
parent | m + add libsimple_random_bytes (diff) | |
download | libsimple-31d1ea0664925ff638c4b30c89cc31dcc93e809b.tar.gz libsimple-31d1ea0664925ff638c4b30c89cc31dcc93e809b.tar.bz2 libsimple-31d1ea0664925ff638c4b30c89cc31dcc93e809b.tar.xz |
Fix libsimple_random_bytes
Signed-off-by: Mattias Andrée <maandree@kth.se>
-rw-r--r-- | random_bytes.c | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/random_bytes.c b/random_bytes.c index cd7416f..723fc63 100644 --- a/random_bytes.c +++ b/random_bytes.c @@ -10,7 +10,8 @@ libsimple_random_bytes(uintmax_t (*rng)(size_t bits, void *user), void *user, vo uintmax_t rnd; while (bytes >= sizeof(uintmax_t)) { - *(uintmax_t *)buf = (*rng)(sizeof(uintmax_t) * 8U, user); + rnd = (*rng)(sizeof(uintmax_t) * 8U, user); + memcpy(buf, &rnd, sizeof(uintmax_t)); bytes -= sizeof(uintmax_t); buf = &buf[sizeof(uintmax_t)]; } @@ -19,6 +20,7 @@ libsimple_random_bytes(uintmax_t (*rng)(size_t bits, void *user), void *user, vo rnd = (*rng)(bytes * 8U, user); while (bytes) { *buf++ = (char)(rnd & 255U); + bytes--; rnd >>= 8; } } |