Subject: [Boost-bugs] [Boost C++ Libraries] #2428: [random] missing member initialization of generator_iterator ctor
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2008-10-22 11:18:49
#2428: [random] missing member initialization of generator_iterator ctor
----------------------------------------------------+-----------------------
Reporter: Johannes Brunen <JBrunen_at_[hidden]> | Owner: no-maintainer
Type: Bugs | Status: new
Milestone: Boost 1.37.0 | Component: random
Version: Boost 1.36.0 | Severity: Problem
Keywords: generator_iterator default ctor |
----------------------------------------------------+-----------------------
I am trying to use boost::generator_iterator with a random number
generator as follows:
---
#include <boost/generator_iterator.hpp>
#include <boost/random/mersenne_twister.hpp>
class my_generator {...};
my_generator gen;
boost::generator_iterator<my_generator> first(&gen);
boost::generator_iterator<my_generator> last;
boost::random::mt19937 rng; rng.seed(first, last);
---
Sadly the default constructor of generator_iterator leaves m_gen
uninitialized and the seed function is trying to compare first
with last.
This yield undefined behavior.
Solution: default ctor member initialization:
generator_iterator.hpp : line 38
generator_iterator() : m_g(0), m_value(0) {}
-- Ticket URL: <http://svn.boost.org/trac/boost/ticket/2428> 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:49:59 UTC