public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
From: Benjamin Kosnik <bkoz@redhat.com>
To: bkoz@gcc.gnu.org
Cc: gcc-prs@gcc.gnu.org,
Subject: Re: libstdc++/8230: Buggy allocator behaviour
Date: Wed, 20 Nov 2002 18:19:00 -0000	[thread overview]
Message-ID: <20021114194604.27476.qmail@sources.redhat.com> (raw)

The following reply was made to PR libstdc++/8230; it has been noted by GNATS.

From: Benjamin Kosnik <bkoz@redhat.com>
To: Gabriel Dos Reis <gdr@integrable-solutions.net>
Cc: bkoz@gcc.gnu.org, gcc-bugs@gcc.gnu.org, jkanze@caicheuvreux.com,
   gcc-gnats@gcc.gnu.org, libstdc++@gcc.gnu.org
Subject: Re: libstdc++/8230: Buggy allocator behaviour
Date: Thu, 14 Nov 2002 13:44:01 -0600

 This is a multi-part message in MIME format.
 
 --Multipart_Thu__14_Nov_2002_13:44:01_-0600_0841f4a0
 Content-Type: text/plain; charset=US-ASCII
 Content-Transfer-Encoding: 7bit
 
 
 >20.4.1.1 allocator members
 >
 >2/
 >  pointer allocator(size_type n, allocator<void>::const_pointer = 0);
 >
 >7/
 >  Throws: bad_alloc if the storage cannot be obtained
 
 Got it, thanks for the clarification.
 
 >int main()
 >{
 >   try {
 >      std::allocator<int> alloc;
 >      const std::allocator<int>::size_type n = alloc.max_size();
 >      int* p = alloc.allocate(n + 1);
 >      p[n] = 2002;
 >      std::cout << p[n] << std::endl;
 >   } catch(const std::bad_alloc& e) {
 >      std::cerr << e.what() << std::endl;
 >   }
 >}
 >This coredumps on my machine using current source.  The problem here is
 >that std::allocator<> is not checking the bounds as required and it is
 >lying.
 
 Correct, with the pool allocators. If you add GLIBCPP_FORCE_NEW
 everything is ok.
 
 See attached patch for a way to fix this with the pool allocators.
 >
 >I'm also nervous about:
 >
 >   std::vector<int> v;
 >   v.resize(v.max_size());
 >
 >   v[v.max_size() - 1] = 2002;
 >
 >I didn't test it with your patch.
 
 My patch is only for reserve, as it's expected to throw length_error.
 I believe it's still correct, regardless of resolving this issue.
 For resize, the above issue comes into play.
 
 On a completely unrelated note, what's up with std::vector and all the gooey 
 allocator typedefs? Ick.
 
 The allocator_type typedef is always allocator, as far as I can tell.
 And _Alloc_type (should be __underlying_allocator or whatever) seems
 superfluous. Instead of typedefing the base type all the time, with g++
 one can just use the name of the template proper. There's got to be a
 cleaner way to do a lot of this. Matt?
 
 best,
 benjamin
 --Multipart_Thu__14_Nov_2002_13:44:01_-0600_0841f4a0
 Content-Type: application/octet-stream;
  name="p.20021114-1"
 Content-Disposition: attachment;
  filename="p.20021114-1"
 Content-Transfer-Encoding: base64
 
 SW5kZXg6IHN0bF9hbGxvYy5oCj09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09
 PT09PT09PT09PT09PT09PT09PT09PT09PT09PT0KUkNTIGZpbGU6IC9jdnMvZ2NjL2djYy9saWJz
 dGRjKystdjMvaW5jbHVkZS9iaXRzL3N0bF9hbGxvYy5oLHYKcmV0cmlldmluZyByZXZpc2lvbiAx
 LjI1CmRpZmYgLWMgLXAgLXIxLjI1IHN0bF9hbGxvYy5oCioqKiBzdGxfYWxsb2MuaAkxOCBPY3Qg
 MjAwMiAyMDo1Mjo1NSAtMDAwMAkxLjI1Ci0tLSBzdGxfYWxsb2MuaAkxNCBOb3YgMjAwMiAxOToz
 NTo0NyAtMDAwMAoqKioqKioqKioqKioqKiogbmFtZXNwYWNlIHN0ZAoqKiogNjY5LDY4MSAqKioq
 CiAgICAgICAgY29uc3RfcG9pbnRlcgogICAgICAgIGFkZHJlc3MoY29uc3RfcmVmZXJlbmNlIF9f
 eCkgY29uc3QgeyByZXR1cm4gJl9feDsgfQogIAohICAgICAgIC8vIF9fbiBpcyBwZXJtaXR0ZWQg
 dG8gYmUgMC4gIFRoZSBDKysgc3RhbmRhcmQgc2F5cyBub3RoaW5nIGFib3V0IHdoYXQKISAgICAg
 ICAvLyB0aGUgcmV0dXJuIHZhbHVlIGlzIHdoZW4gX19uID09IDAuCiAg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YW5kIHNvbWUgb2Yg
 dGhlbSBkb24ndCB0aHJvdwohIAkgICAgLy8gYmFkX2FsbG9jIGJ5IGRlZmF1bHQgaWYgdGhleSBm
 YWlsLiBUaHVzLCBhZGQgdGhlIGNoZWNrCiEgCSAgICAvLyBiZWxvdy4KISAJICAgIF9fcmV0ID0g
 c3RhdGljX2Nhc3Q8X1RwKj4oX0FsbG9jOjphbGxvY2F0ZShfX24gKiBzaXplb2YoX1RwKSkpOwoh
 IAkgICAgaWYgKCFfX3JldCkKISAJICAgICAgX190aHJvd19iYWRfYWxsb2MoImFsbG9jYXRvcjo6
 YWxsb2NhdGUiKTsKISAJICB9CiEgCXJldHVybiBfX3JldDsKICAgICAgICB9CiAgCiAgICAgICAg
 Ly8gX19wIGlzIG5vdCBwZXJtaXR0ZWQgdG8gYmUgYSBudWxsIHBvaW50ZXIuCg==
 
 --Multipart_Thu__14_Nov_2002_13:44:01_-0600_0841f4a0--


             reply	other threads:[~2002-11-14 19:46 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-11-20 18:19 Benjamin Kosnik [this message]
  -- strict thread matches above, loose matches on Subject: below --
2002-11-23  1:16 bkoz
2002-11-21 14:01 Richard Henderson
2002-11-21  4:06 Gabriel Dos Reis
2002-11-21  3:47 Matt Austern
2002-11-20 23:03 Gabriel Dos Reis
2002-11-20 19:09 Gabriel Dos Reis
2002-11-20 18:20 Benjamin Kosnik
2002-11-20 18:02 Gabriel Dos Reis
2002-11-20  5:07 bkoz
2002-10-15  5:56 gdr

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=20021114194604.27476.qmail@sources.redhat.com \
    --to=bkoz@redhat.com \
    --cc=bkoz@gcc.gnu.org \
    --cc=gcc-prs@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: link
Be 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).