// $Id: yasli_vector.h 754 2006-10-17 19:59:11Z syntheticpp $
The implementation for yasli::vector::insert (line 402) uses the position parameter _after_ a call to reserve. But if the call to reserve resulted in a memory reallocation, this iterator has become invalid. Consequently, 'pos' on line 406 is incorrect and the insert call in line 407 also does "the wrong thing"TM.
The solution is to calculate pos _before_ the reserve call and recalculate position from that _after_ the reserve call.
const size_type pos = position - begin();
reserve(size() + 1);
position = begin() + pos;
insert(position, (size_type)1, x);
return ebo_.beg_ + pos;
Log in to post a comment.