From 31d1ea0664925ff638c4b30c89cc31dcc93e809b Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Tue, 17 Sep 2024 21:59:29 +0200 Subject: Fix libsimple_random_bytes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- random_bytes.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'random_bytes.c') 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; } } -- cgit v1.2.3-70-g09d2