This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug libstdc++/31370] resizing bugs in std::vector<bool>



------- Comment #6 from gcc at severeweblint dot org  2007-03-27 20:27 -------
4.2 doesn't fix any of the problems, but it does make the max_size
issue a bit more confusing.

There is a subtle relationship between vector size and
pointers. Pointers can address only SIZE_MAX memory. But iterators
takes ssize_t as arguments to addition and subtraction operators, so
vector size should be limited to SSIZE_MAX. For sizeof(_Tp) of at
least 2 bytes, there is no problem. The pointer limitation implies a
size limit of SIZE_MAX / sizeof(_Tp) which is less than SSIZE_MAX. For
sizeof(_Tp) of one byte, things deserve to be broken, but manage
not to be. The fact that for two size_t x1 and x2, it is always true
that size_t(x1+x2) == size_t(x1+ssize_t(y)) manages to rescue the
situation.

But for vector<bool>, things break down completely and the max_size
becomes limited by SSIZE_MAX, not the pointer limitation. Worse,
because of the round up to the nearest word, the max_size actually has
to be SSIZE_MAX rounded DOWN to the nearest word. 

So allowing for the allocator to have its own size limit, the
implementation of max_size has to become

size_type
max_size() const
{   
  const size_type __isize = SSIZE_MAX - int(_S_word_bit) + 1;
  const size_type __asize = _M_get_Bit_allocator().max_size(); 
  return (__asize < __isize / size_type(_S_word_bit) ?
          __asize * size_type(_S_word_bit) : __isize);
}

Note that it probably isn't correct to assume that difference_type is
a ssize_t, and therefore has maximum SSIZE_MAX, but I don't see what
the correct way to ask what the maximum value representable by
difference_type is.

I'm fine with filling out copyright assignment paperwork, but I didn't see the
form at the link you gave me.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31370


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]