From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 19435 invoked by alias); 27 Mar 2007 19:27:16 -0000 Received: (qmail 19413 invoked by uid 48); 27 Mar 2007 19:27:02 -0000 Date: Tue, 27 Mar 2007 19:27:00 -0000 Message-ID: <20070327192702.19412.qmail@sourceware.org> X-Bugzilla-Reason: CC References: Subject: [Bug libstdc++/31370] resizing bugs in std::vector In-Reply-To: Reply-To: gcc-bugzilla@gcc.gnu.org To: gcc-bugs@gcc.gnu.org From: "gcc at severeweblint dot org" Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2007-03/txt/msg02608.txt.bz2 ------- 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, 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