Commit 486c6593 authored by Matt Glazar's avatar Matt Glazar Committed by Facebook Github Bot

Improve assertion messages from Random::secureRandom

Summary:
When the PCHECK for read() in Random::secureRandom fails, the message is often misleading.

In the following case, bytesRead != size caused the assertion failure. Unfortunately, the message includes an unrelated error message ("No such file or directory"), which can throw people off:

  F1031 13:15:26.997059 270573 Random.cpp:69] Check failed: bytesRead >= 0 && size_t(bytesRead) == size : No such file or directory [2]

Improve the message by splitting the PCHECK into a PCHECK (for the read() error) and a CHECK_EQ (for the logic error):

  F1108 17:33:31.771008 3185333 Random.cpp:70] Check failed: size_t(bytesRead) == size (112960 vs. 1048576)

Reviewed By: yfeldblum, simpkins

Differential Revision: D12856276

fbshipit-source-id: fe9067972db805a54f2cc290aab11bac425601ef
parent 613f048b
......@@ -66,7 +66,8 @@ void readRandomDevice(void* data, size_t size) {
static int randomFd = ::open("/dev/urandom", O_RDONLY | O_CLOEXEC);
PCHECK(randomFd >= 0);
auto bytesRead = readFull(randomFd, data, size);
PCHECK(bytesRead >= 0 && size_t(bytesRead) == size);
PCHECK(bytesRead >= 0);
CHECK_EQ(size_t(bytesRead), size);
#endif
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment