Opened 13 years ago

Closed 13 years ago

Last modified 9 years ago

#3579 closed Bugs (fixed)

[ptr_container] ptr_vector<T>::resize creates uninitialized objects if T is a POD

Reported by: roman.perepelitsa@… Owned by: Thorsten Ottosen
Milestone: Boost 1.41.0 Component: ptr_container
Version: Boost 1.40.0 Severity: Problem
Keywords: ptr_container, ptr_vector Cc: roman.perepelitsa@…

Description

ptr_vector<T>::resize creates new objects using 'new T' instead of 'new T()', which results in uninitialized objects if T is a POD. For consistency with STL containers (std::vector in particular) all PODs must be explicitly initialized.

Test: #include <cassert>

#include <boost/ptr_container/ptr_vector.hpp>

int main() {

boost::ptr_vector<int> v;

v.resize(1);

assert(v[0] == 0); Might fail.

}

ptr_circullar_buffer has the same problem.

I'm attaching a patch that fixes the problem.

Attachments (1)

ptr_container.diff (1.9 KB ) - added by roman.perepelitsa@… 13 years ago.
Patch with the fix

Download all attachments as: .zip

Change History (5)

by roman.perepelitsa@…, 13 years ago

Attachment: ptr_container.diff added

Patch with the fix

comment:1 by Steven Watanabe, 13 years ago

Component: Noneptr_container
Owner: set to Thorsten Ottosen

comment:2 by anonymous, 13 years ago

Resolution: fixed
Status: newclosed

Patch applied to trunk.

Thanks

-Thorsten

comment:3 by roman.perepelitsa@…, 13 years ago

That was fast. Thanks!

comment:4 by anonymous, 9 years ago

class boost::ptr_vector<XXX, boost::heap_clone_allocator, std::allocator<void*> >' has no member named 'resize'

Note: See TracTickets for help on using tickets.