Subject: [Boost-bugs] [Boost C++ Libraries] #3971: basic_random_generator doesn't produce a fully randomized uuid when sizeof(unsigned long) == 4
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2010-03-03 10:37:37
#3971: basic_random_generator doesn't produce a fully randomized uuid when
sizeof(unsigned long) == 4
--------------------------------------------------+-------------------------
Reporter: gareth.sylvester-bradley@⦠| Owner: atompkins
Type: Patches | Status: new
Milestone: Boost 1.43.0 | Component: uuid
Version: Boost 1.42.0 | Severity: Problem
Keywords: |
--------------------------------------------------+-------------------------
There is a flaw in basic_random_generator<>
(boost/uuid/uuid_generators.hpp, line 366-374) that means it will only
generate about 4 billion different values before a collision on the many
platforms where sizeof(unsigned long) == 4.
On these platforms the first 8 bytes of the uuid are populated with random
data, but the contents of the remaining 8 bytes are undefined.
In my tests they are populated with repeated data, due to Microsoft's
specific implementation for the undefined behaviour of >> when its "right
operand is greater than or equal to the length in bits of the promoted
left operand."
For example, try the following test program with a Win32 build by Visual
C++ 9.0 â
{{{
#include <iostreams>
#include <boost/uuid/uuid_generators.hpp>
#include <boost/uuid/uuid_io.hpp>
int main( int, char*[] )
{
std::cout << boost::uuids::random_generator()() << std::endl;
return 0;
}
}}}
This produced for me:
{{{
f1633d75-ee94-47b9-ae94-37b9ee9437b9
}}}
Or wrapped to show the problem:
{{{
f1633d75-
ee94-47b9-
ae94-37b9
ee94 37b9
}}}
The simplest patch could be just:
{{{
370a370
> i=0;
}}}
-- Ticket URL: <https://svn.boost.org/trac/boost/ticket/3971> Boost C++ Libraries <http://www.boost.org/> Boost provides free peer-reviewed portable C++ source libraries.
This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:02 UTC