aboutsummaryrefslogtreecommitdiff
path: root/src/os.cpp
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2019-03-07 13:04:10 -0500
committerAndrew Kelley <andrew@ziglang.org>2019-03-07 13:04:10 -0500
commite2ce00f272acdf3a0b5bdb3f9322aa1c487c483d (patch)
tree3d54be5c7ed157c65bc321d035a13e3a9d696284 /src/os.cpp
parentffaa4f0a87af60718062c3a9eeab9fb354731241 (diff)
downloadzig-e2ce00f272acdf3a0b5bdb3f9322aa1c487c483d.tar.gz
zig-e2ce00f272acdf3a0b5bdb3f9322aa1c487c483d.zip
fix regressions on macos
Diffstat (limited to 'src/os.cpp')
-rw-r--r--src/os.cpp10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/os.cpp b/src/os.cpp
index 9a42859610..ac3bbc721c 100644
--- a/src/os.cpp
+++ b/src/os.cpp
@@ -1414,13 +1414,17 @@ static void init_rand() {
if (fd == -1) {
zig_panic("unable to open /dev/urandom");
}
- const char bytes[sizeof(unsigned)];
- unsigned seed;
- while (read(fd, bytes, sizeof(unsigned)) == -1) {
+ char bytes[sizeof(unsigned)];
+ size_t amt_read;
+ while ((amt_read = read(fd, bytes, sizeof(unsigned))) == -1) {
if (errno == EINTR) continue;
zig_panic("unable to read /dev/urandom");
}
+ if (amt_read != sizeof(unsigned)) {
+ zig_panic("unable to read enough bytes from /dev/urandom");
+ }
close(fd);
+ unsigned seed;
memcpy(&seed, bytes, sizeof(unsigned));
srand(seed);
#endif