[v3] libstdc++/57920

Paolo Carlini paolo.carlini@oracle.com
Mon Jul 22 13:04:00 GMT 2013


Hi,

see audit trail for details. I tested on x86_64-linux (with/without 
_GLIBCXX_X86_RDRAND artificially undefined) the below straightforward 
patch and checked by hand the strace. I'm going to apply it soon.

Thanks,
Paolo.

///////////////////
-------------- next part --------------
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.
-------------- next part --------------
Index: include/std/random
===================================================================
--- include/std/random	(revision 201122)
+++ include/std/random	(working copy)
@@ -36,7 +36,6 @@
 #else
 
 #include <cmath>
-#include <cstdio>
 #include <cstdlib>
 #include <string>
 #include <iosfwd>
Index: src/c++11/random.cc
===================================================================
--- src/c++11/random.cc	(revision 201122)
+++ src/c++11/random.cc	(working copy)
@@ -30,7 +30,12 @@
 # include <cpuid.h>
 #endif
 
+#include <cstdio>
 
+#ifdef _GLIBCXX_HAVE_UNISTD_H
+# include <unistd.h>
+#endif
+
 namespace std _GLIBCXX_VISIBILITY(default)
 {
 
@@ -126,8 +131,12 @@
 #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;
   }
 


More information about the Gcc-patches mailing list