Opened 11 years ago

#6072 new Bugs

Bad iterator difference for m.begin1() - m.end1() in ublas

Reported by: Robin Palotai <palotai.robin@…> Owned by: Gunter
Milestone: To Be Determined Component: uBLAS
Version: Boost 1.47.0 Severity: Problem
Keywords: iterator, distance Cc:

Description

In functional.hpp at a couple of places, for example:

static BOOST_UBLAS_INLINE difference_type distance_i (difference_type k, size_type /* size_i */, size_type size_j) {

return size_j != 0 ? k / size_j : 0;

}

k [ / | % ] size_[ i | j ] is used, where k is difference_type (signed), size_i|j is size_type (unsigned). This results in promoting k to unsigned, and can yield very strange results when k is negative.

For example, m being a size 2x2 ublas::matrix, m.begin1() - m.end1() yields 2147483646 instead of -2.

Putting a static_cast<difference_type>(size_i|j) in functional.hpp seems to solve the problem.

Change History (0)

Note: See TracTickets for help on using tickets.