diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2019-03-07 13:04:10 -0500 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2019-03-07 13:04:10 -0500 |
| commit | e2ce00f272acdf3a0b5bdb3f9322aa1c487c483d (patch) | |
| tree | 3d54be5c7ed157c65bc321d035a13e3a9d696284 /src/os.cpp | |
| parent | ffaa4f0a87af60718062c3a9eeab9fb354731241 (diff) | |
| download | zig-e2ce00f272acdf3a0b5bdb3f9322aa1c487c483d.tar.gz zig-e2ce00f272acdf3a0b5bdb3f9322aa1c487c483d.zip | |
fix regressions on macos
Diffstat (limited to 'src/os.cpp')
| -rw-r--r-- | src/os.cpp | 10 |
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 |
