Subject: [Boost-bugs] [Boost C++ Libraries] #6072: Bad iterator difference for m.begin1() - m.end1() in ublas
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2011-10-30 12:20:23
#6072: Bad iterator difference for m.begin1() - m.end1() in ublas
-----------------------------------------------------+----------------------
Reporter: Robin Palotai <palotai.robin@â¦> | Owner: guwi17
Type: Bugs | Status: new
Milestone: To Be Determined | Component: uBLAS
Version: Boost 1.47.0 | Severity: Problem
Keywords: iterator, distance |
-----------------------------------------------------+----------------------
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.
-- Ticket URL: <https://svn.boost.org/trac/boost/ticket/6072> 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:07 UTC