From 94e7477f0cb3a9b7d0523d2c2fbf039ab19cf081 Mon Sep 17 00:00:00 2001 From: Paolo Carlini <paolo.carlini@oracle.com> Date: Mon, 22 Jul 2013 15:22:52 +0000 Subject: [PATCH] re PR libstdc++/57920 ([c++11] Linux: std::random_device reads too much from /dev/urandom) 2013-07-22 Paolo Carlini <paolo.carlini@oracle.com> PR c++/57920 * src/c++11/random.cc (random_device::_M_getval): If possible, use read instead of std::fread. * include/std/random: Do not include <cstdio> unnecessarily. From-SVN: r201133 --- libstdc++-v3/ChangeLog | 7 +++++++ libstdc++-v3/include/std/random | 1 - libstdc++-v3/src/c++11/random.cc | 9 +++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 67cb99602c23..cd87d9484872 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,10 @@ +2013-07-22 Paolo Carlini <paolo.carlini@oracle.com> + + PR c++/57920 + * src/c++11/random.cc (random_device::_M_getval): If possible, use + read instead of std::fread. + * include/std/random: Do not include <cstdio> unnecessarily. + 2013-07-21 Tim Shen <timshen91@gmail.com> Partially implement regex_search. diff --git a/libstdc++-v3/include/std/random b/libstdc++-v3/include/std/random index ceb38252cd93..84b176154b9b 100644 --- a/libstdc++-v3/include/std/random +++ b/libstdc++-v3/include/std/random @@ -36,7 +36,6 @@ #else #include <cmath> -#include <cstdio> #include <cstdlib> #include <string> #include <iosfwd> diff --git a/libstdc++-v3/src/c++11/random.cc b/libstdc++-v3/src/c++11/random.cc index 2bd713260a21..1646786882ad 100644 --- a/libstdc++-v3/src/c++11/random.cc +++ b/libstdc++-v3/src/c++11/random.cc @@ -30,6 +30,11 @@ # include <cpuid.h> #endif +#include <cstdio> + +#ifdef _GLIBCXX_HAVE_UNISTD_H +# include <unistd.h> +#endif namespace std _GLIBCXX_VISIBILITY(default) { @@ -126,8 +131,12 @@ namespace std _GLIBCXX_VISIBILITY(default) #endif result_type __ret; +#ifdef _GLIBCXX_HAVE_UNISTD_H + read(fileno(_M_file), reinterpret_cast<void*>(&__ret), sizeof(result_type)); +#else std::fread(reinterpret_cast<void*>(&__ret), sizeof(result_type), 1, _M_file); +#endif return __ret; } -- GitLab