This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ 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]

Re: libstdc++/8230: Buggy allocator behaviour


Benjamin Kosnik <bkoz@redhat.com> writes:

[...]

| >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.

Thanks!

| 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.

Yes, you're right.

| 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.

[ I'm not sure I understand correctly which part you're referring to.
  I'll try answer what I understood from your question.  Please don't
  hesitate to correct me if I'm on the wrong track.  ]

Well, the allocator_type typedef game is what we've got to write to
simulate "typedef template".  Basically one wants to be able to get an
allocator for the familly of allocator supplied to std::vector<>.

| 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.

Probably not the name of the template but the name of the
template-parameter _Alloc.  But, I suspect that for not duplicating
the way the allocator is referred to, it is just safe to use
_Base::allocator_type -- note that we have to typedef that name to
allocator_type in std::vector<> anyway.

Maybe Matt has better explanations.

-- Gaby


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