Re: [Boost-bugs] [Boost C++ Libraries] #10980: boost::random::random_device bug with /dev/random

Subject: Re: [Boost-bugs] [Boost C++ Libraries] #10980: boost::random::random_device bug with /dev/random
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2015-01-29 08:11:08


#10980: boost::random::random_device bug with /dev/random
-------------------------------------------------+-------------------------
  Reporter: Bastiaan Stougie | Owner: no-
  <bastiaan.stougie@…> | maintainer
      Type: Bugs | Status: new
 Milestone: To Be Determined | Component: random
   Version: Boost 1.56.0 | Severity: Problem
Resolution: | Keywords:
                                                 | random_device
-------------------------------------------------+-------------------------

Comment (by Bastiaan Stougie <bastiaan.stougie@…>):

 Here's a patch:

 {{{

 diff --git a/libs/random/src/random_device.cpp
 b/libs/random/src/random_device.cpp
 --- a/libs/random/src/random_device.cpp
 +++ b/libs/random/src/random_device.cpp
 @@ -168,13 +168,17 @@

    unsigned int next() {
          unsigned int result;
     - long sz = read(fd, reinterpret_cast<char *>(&result),
 sizeof(result));
     - if(sz == -1)
     - error("error while reading");
     - else if(sz != sizeof(result)) {
     - errno = 0;
     - error("EOF while reading");
     - }
     + size_t offset = 0;
     + do {
     + long sz = read(fd, reinterpret_cast<char *>(&result) + offset,
 sizeof(result) - offset);
     + if(sz == -1)
     + error("error while reading");
     + else if(sz == 0) {
     + errno = 0;
     + error("EOF while reading");
     + }
     + offset += sz;
     + } while (offset < sizeof(result));
          return result;
        }

 }}}

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/10980#comment:1>
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:17 UTC