diff --git a/src/random.cpp b/src/random.cpp index bd24f2e50..21e21689a 100644 --- a/src/random.cpp +++ b/src/random.cpp @@ -49,7 +49,7 @@ random_device::operator()() random_device::random_device(const string& __token) : __f_(open(__token.c_str(), O_RDONLY)) { - if (__f_ <= 0) + if (__f_ < 0) __throw_system_error(errno, ("random_device failed to open " + __token).c_str()); } diff --git a/test/numerics/rand/rand.device/ctor.pass.cpp b/test/numerics/rand/rand.device/ctor.pass.cpp index a7c38d4c1..dfa546be7 100644 --- a/test/numerics/rand/rand.device/ctor.pass.cpp +++ b/test/numerics/rand/rand.device/ctor.pass.cpp @@ -15,6 +15,7 @@ #include #include +#include int main() { @@ -29,6 +30,16 @@ int main() { std::random_device r; } + { + int ec; + ec = close(STDIN_FILENO); + assert(!ec); + ec = close(STDOUT_FILENO); + assert(!ec); + ec = close(STDERR_FILENO); + assert(!ec); + std::random_device r; + } { std::random_device r("/dev/urandom");; }