aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--random_bytes.c4
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;
}
}