summaryrefslogtreecommitdiffstats
path: root/libcxx/test/numerics/rand
diff options
context:
space:
mode:
authorDavid Majnemer <david.majnemer@gmail.com>2014-06-03 02:21:37 +0000
committerDavid Majnemer <david.majnemer@gmail.com>2014-06-03 02:21:37 +0000
commit1e9592a9c71ed87c806946ad2cccc1bcb472324d (patch)
tree847dbc2f903eda47bd45c8abcce95ed631da1ab8 /libcxx/test/numerics/rand
parentcf2048bbb3c3340e676fa166b2afd68e9ebf4e8d (diff)
downloadbcm5719-llvm-1e9592a9c71ed87c806946ad2cccc1bcb472324d.tar.gz
bcm5719-llvm-1e9592a9c71ed87c806946ad2cccc1bcb472324d.zip
[libc++] random_device fails if open returns zero
random_device::random_device(const string&) wrongly assumes that open can only validly return a file descriptor greater than zero. This results in random_device believing that it didn't successfully open the device causing it to throw in it's constructor, this ends up leaking a file descriptor. The fix is simple, don't error on file descriptors which are zero. llvm-svn: 210060
Diffstat (limited to 'libcxx/test/numerics/rand')
-rw-r--r--libcxx/test/numerics/rand/rand.device/ctor.pass.cpp11
1 files changed, 11 insertions, 0 deletions
diff --git a/libcxx/test/numerics/rand/rand.device/ctor.pass.cpp b/libcxx/test/numerics/rand/rand.device/ctor.pass.cpp
index a7c38d4c165..dfa546be709 100644
--- a/libcxx/test/numerics/rand/rand.device/ctor.pass.cpp
+++ b/libcxx/test/numerics/rand/rand.device/ctor.pass.cpp
@@ -15,6 +15,7 @@
#include <random>
#include <cassert>
+#include <unistd.h>
int main()
{
@@ -30,6 +31,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");;
}
{
OpenPOWER on IntegriCloud