Opened 11 years ago

#6626 new Bugs

shallow_array_adaptor bug in swap function

Reported by: Guillermo Ruiz Troyano <ruiztroyano@…> Owned by: Gunter
Milestone: Boost 1.50.0 Component: uBLAS
Version: Boost 1.49.0 Severity: Problem
Keywords: boost::numeric::ublas::shallow_array_adaptor Cc:

Description

boost::numeric::ublas::vector< T,shallow_array_adaptor<T> > fails when it is assigned with an expression. For example:

#define BOOST_UBLAS_SHALLOW_ARRAY_ADAPTOR
#include <boost/numeric/ublas/vector.hpp>

struct point {
   double x;
   double y;
   double z;
};

void test() {
   using namespace boost::numeric::ublas;

   point p = { 1, 2, 3 }
   shallow_array_adaptor<double> a(3, &p.x);            // Ok, a holds p address
   vector<double, shallow_array_adaptor<double> > v(a); // Ok, v holds p address
   
   v += v;     // Ok, now p = { 2, 4, 6 }
   v /= 2;     // Ok, now p = { 1, 2, 3 }
   v = v*2;    // <- Oh no, p = { 1, 2, 3 } !!!
}

vector creates a temporary object and it calls to shallow_array_adaptor::swap. This function doesn't check if it is the owner of pointers to swap. When both are data owners can do that (as unbounded_array does). But if they are not then they should swap as bounded_array does.

Attachments (1)

patchfile.patch (1.1 KB ) - added by Guillermo Ruiz Troyano <ruiztroyano@…> 11 years ago.
Patch of boost::numeric::ublas::shallow_array_adaptor::swap

Download all attachments as: .zip

Change History (1)

by Guillermo Ruiz Troyano <ruiztroyano@…>, 11 years ago

Attachment: patchfile.patch added

Patch of boost::numeric::ublas::shallow_array_adaptor::swap

Note: See TracTickets for help on using tickets.