Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r60985 - in trunk: boost/uuid libs/uuid
From: atompkins_at_[hidden]
Date: 2010-03-31 22:42:21


Author: atompkins
Date: 2010-03-31 22:42:20 EDT (Wed, 31 Mar 2010)
New Revision: 60985
URL: http://svn.boost.org/trac/boost/changeset/60985

Log:
Added notes to documentation about using Valgrind
Added some comments to seed_rng.hpp
Text files modified:
   trunk/boost/uuid/seed_rng.hpp | 4 ++++
   trunk/libs/uuid/uuid.html | 13 +++++++++++++
   2 files changed, 17 insertions(+), 0 deletions(-)

Modified: trunk/boost/uuid/seed_rng.hpp
==============================================================================
--- trunk/boost/uuid/seed_rng.hpp (original)
+++ trunk/boost/uuid/seed_rng.hpp 2010-03-31 22:42:20 EDT (Wed, 31 Mar 2010)
@@ -75,6 +75,7 @@
     //BOOST_STATIC_CONSTANT(unsigned int, max_value = UINT_MAX);
 
 public:
+ // note: rd_ intentionally left uninitialized
     seed_rng()
         : rd_index_(5)
         , random_(std::fopen( "/dev/urandom", "rb" ))
@@ -111,6 +112,7 @@
 private:
     static unsigned int * sha1_random_digest_state_()
     {
+ // intentionally left uninitialized
         static unsigned int state[ 5 ];
         return state;
     }
@@ -143,6 +145,7 @@
         }
 
         {
+ // intentionally left uninitialized
             unsigned char buffer[ 20 ];
 
             if(random_)
@@ -156,6 +159,7 @@
         }
 
         {
+ // *p is intentionally left uninitialized
             unsigned int * p = new unsigned int;
 
             sha.process_bytes( (unsigned char const*)p, sizeof( *p ) );

Modified: trunk/libs/uuid/uuid.html
==============================================================================
--- trunk/libs/uuid/uuid.html (original)
+++ trunk/libs/uuid/uuid.html 2010-03-31 22:42:20 EDT (Wed, 31 Mar 2010)
@@ -587,6 +587,19 @@
 values including <tt>std::time(0)</tt>, <tt>std::clock()</tt>, uninitialized
 data, value return from <tt>new unsigned int</tt>, etc..
 
+<p>Using Valgrind produces a number of false
+positives with the default constructor of <tt>boost::uuids::basic_random_generator</tt>.
+One solution is to suppress the errors as described in
+Valgrind's documentation.
+Another solution is to use a different constructor of <tt>boost::uuids::basic_random_generator</tt>
+and explicitly pass in a random number generator.
+<pre>
+boost::mt19937 ran;
+ran.seed(time(NULL)); // one should likely seed in a better way
+boost::uuids::basic_random_generator&lt;boost::mt19937&gt; gen(&ran);
+boost::uuids::uuid u = gen();
+</pre>
+
 <p>The <tt>boost::uuids::name_generator</tt> class uses the SHA-1 hash function to
 compute the <b>uuid</b>.
 


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk