diff options
author | kwolekr <kwolekr@minetest.net> | 2015-03-23 21:07:32 -0400 |
---|---|---|
committer | kwolekr <kwolekr@minetest.net> | 2015-03-23 22:23:16 -0400 |
commit | 9fc2b93d9ff7fdde1695e52aec877e98d5cc1e39 (patch) | |
tree | 1db693cd599b337aa62700d44336e06e6bceb1e2 /src | |
parent | a423202756744c4f09488762ed35ab24693b0f20 (diff) | |
download | minetest-9fc2b93d9ff7fdde1695e52aec877e98d5cc1e39.tar.gz minetest-9fc2b93d9ff7fdde1695e52aec877e98d5cc1e39.tar.bz2 minetest-9fc2b93d9ff7fdde1695e52aec877e98d5cc1e39.zip |
Fix endianness inconsistency with PcgRandom::bytes()
Diffstat (limited to 'src')
-rw-r--r-- | src/noise.cpp | 35 |
1 files changed, 10 insertions, 25 deletions
diff --git a/src/noise.cpp b/src/noise.cpp index c36b33db8..bb7c9969e 100644 --- a/src/noise.cpp +++ b/src/noise.cpp @@ -123,35 +123,20 @@ s32 PcgRandom::range(s32 min, s32 max) void PcgRandom::bytes(void *out, size_t len) { - u32 r; u8 *outb = (u8 *)out; + int bytes_left = 0; + u32 r; - size_t len_alignment = (uintptr_t)out % sizeof(u32); - if (len_alignment) { - len -= len_alignment; - r = next(); - while (len_alignment--) { - *outb = r & 0xFF; - outb++; - r >>= 8; + while (len--) { + if (bytes_left == 0) { + bytes_left = sizeof(u32); + r = next(); } - } - size_t len_dwords = len / sizeof(u32); - while (len_dwords--) { - r = next(); - *(u32 *)outb = next(); - outb += sizeof(u32); - } - - size_t len_remaining = len % sizeof(u32); - if (len_remaining) { - r = next(); - while (len_remaining--) { - *outb = r & 0xFF; - outb++; - r >>= 8; - } + *outb = r & 0xFF; + outb++; + bytes_left--; + r >>= 8; } } |