public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "gcc at severeweblint dot org" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/31370] resizing bugs in std::vector<bool> Date: Tue, 27 Mar 2007 19:27:00 -0000 [thread overview] Message-ID: <20070327192702.19412.qmail@sourceware.org> (raw) In-Reply-To: <bug-31370-14320@http.gcc.gnu.org/bugzilla/> ------- 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
next prev parent reply other threads:[~2007-03-27 19:27 UTC|newest] Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top 2007-03-27 3:03 [Bug libstdc++/31370] New: resizing bugs in std::vector gcc at severeweblint dot org 2007-03-27 3:09 ` [Bug libstdc++/31370] " gcc at severeweblint dot org 2007-03-27 3:20 ` gcc at severeweblint dot org 2007-03-27 6:05 ` [Bug libstdc++/31370] resizing bugs in std::vector<bool> pinskia at gcc dot gnu dot org 2007-03-27 7:52 ` fang at csl dot cornell dot edu 2007-03-27 8:07 ` pcarlini at suse dot de 2007-03-27 19:27 ` gcc at severeweblint dot org [this message] 2007-03-27 20:03 ` pcarlini at suse dot de 2007-03-31 16:52 ` pcarlini at suse dot de 2007-04-02 10:16 ` paolo at gcc dot gnu dot org 2007-04-02 10:19 ` pcarlini at suse dot de
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20070327192702.19412.qmail@sourceware.org \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).