public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
From: Gabriel Dos Reis <gdr@integrable-solutions.net>
To: bkoz@gcc.gnu.org
Cc: gcc-prs@gcc.gnu.org,
Subject: Re: libstdc++/8230: Buggy allocator behaviour
Date: Wed, 20 Nov 2002 18:02:00 -0000 [thread overview]
Message-ID: <20021114150601.13602.qmail@sources.redhat.com> (raw)
The following reply was made to PR libstdc++/8230; it has been noted by GNATS.
From: Gabriel Dos Reis <gdr@integrable-solutions.net>
To: bkoz@gcc.gnu.org
Cc: 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: 14 Nov 2002 15:59:43 +0100
bkoz@gcc.gnu.org writes:
| Synopsis: Buggy allocator behaviour
|
| Responsible-Changed-From-To: unassigned->bkoz
| Responsible-Changed-By: bkoz
| Responsible-Changed-When: Wed Nov 13 14:19:11 2002
| Responsible-Changed-Why:
| Mine.
| State-Changed-From-To: open->feedback
| State-Changed-By: bkoz
| State-Changed-When: Wed Nov 13 14:19:11 2002
| State-Changed-Why:
| I don't think this is an allocator::allocate issue per se. The member function reserve is only in std::vector and std::vector<bool>, and the standard says
Hi Benjamin,
This issue is a conjugation of both std::allocator<> and
std::vector<> ill-behaviour. Fixing std::vector<> fixes a part of
the problem (i.e. the testcase provided will pass), but leaves
completely unfixed the std::allocator<> bits as required by the
standard:
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
20.4.1.1/11
size_type max_size() const throw();
returns the largest value N for which the call allocate(N, 0) might
succeed.
Now consider
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.
On fr.comp.lang.c++, I developed a theory to the effect that
std::vector<> may always not check the bounds and still remain
conformant *provided* that the allocator is doing the right thing.
| 23.2.4.2 - vector capacity
|
| -4- Throws: length_error if n > max_size().*
|
| Where allocator::allocate doesn't know what vector::max_size is.
Agreed.
|
| This fix brings the code up to conformance, and is the best fix I think.
It, however, does not address the std::allocator<> ill-behaviour.
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.
-- Gaby
next reply other threads:[~2002-11-14 15:06 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-11-20 18:02 Gabriel Dos Reis [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:19 Benjamin Kosnik
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=20021114150601.13602.qmail@sources.redhat.com \
--to=gdr@integrable-solutions.net \
--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).