Opened 11 years ago

Closed 11 years ago

#5674 closed Patches (fixed)

assertion failed in boost::range::copy_n()

Reported by: farid@… Owned by: Neil Groves
Milestone: Boost 1.50.0 Component: range
Version: Boost 1.46.1 Severity: Problem
Keywords: copy_n Cc:

Description

The program below fails on assert:

#include <boost/range/iterator_range.hpp>
#include <boost/range/algorithm_ext/copy_n.hpp>

int main(int argc, char* argv[])
{
    int src[5] = { 1, 2, 3, 4, 5 };
    int dst[5];

    boost::copy_n(boost::make_iterator_range(src, src + 5), 5, dst);

    return 0;
}
Assertion failed: n < static_cast<Size>(boost::distance(rng)), file boost_1_46_1/boost/range/algorithm_ext/copy_n.hpp, line 38

Proposed patch:

--- boost/range/algorithm_ext/copy_n.hpp
+++ boost/range/algorithm_ext/copy_n.hpp
@@ -30,12 +30,12 @@
 ///
 /// \pre SinglePassRange is a model of the SinglePassRangeConcept
 /// \pre OutputIterator is a model of the OutputIteratorConcept
-/// \pre 0 <= n < distance(rng)
+/// \pre 0 <= n <= distance(rng)
 template< class SinglePassRange, class Size, class OutputIterator >
 inline OutputIterator copy_n(const SinglePassRange& rng, Size n, OutputIterator out)
 {
     BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept<const SinglePassRange> ));
-    BOOST_ASSERT( n < static_cast<Size>(boost::distance(rng)) );
+    BOOST_ASSERT( n <= static_cast<Size>(boost::distance(rng)) );
     BOOST_ASSERT( n >= static_cast<Size>(0) );
 
     BOOST_DEDUCED_TYPENAME range_iterator<const SinglePassRange>::type source = boost::begin(rng);

Change History (1)

comment:1 by Neil Groves, 11 years ago

Milestone: To Be DeterminedBoost 1.50.0
Resolution: fixed
Status: newclosed

Resolved at last on trunk.

Note: See TracTickets for help on using tickets.