From 0505ad5f0b55c5ecfc2445c936d66c14278826bd Mon Sep 17 00:00:00 2001 From: MITSUNARI Shigeo Date: Sun, 5 May 2019 07:44:15 +0900 Subject: [PATCH] return false if RandomGenerator fails init --- include/cybozu/random_generator.hpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/include/cybozu/random_generator.hpp b/include/cybozu/random_generator.hpp index 4a9f071..2e097e3 100644 --- a/include/cybozu/random_generator.hpp +++ b/include/cybozu/random_generator.hpp @@ -104,6 +104,10 @@ private: template void read(bool *pb, T *buf, size_t bufNum) { + if (fp_ == 0) { + *pb = false; + return; + } const size_t byteSize = sizeof(T) * bufNum; *pb = ::fread(buf, 1, (int)byteSize, fp_) == byteSize; }