|
Boost : |
From: Marco Morandini (morandini_at_[hidden])
Date: 2001-07-17 09:50:54
Apologize for the question but
I'm not very expert with C++.
I don't understand if the following behaviour is correct.
If the code is correct, is the problem caused by a
compiler/std library's bug or by a boost's bug?
Compiler: gcc 3.0, linux box
Boost: 1.23.0
The following code leads to a SIGSEG:
--------------------------------------------
#include <boost/smart_ptr.hpp>
#include <vector>
int main(void) {
std::vector<boost::shared_ptr<int> >a;
a.reserve(8);
//a.resize(8);
int * y;
y = new int;
a[0] = boost::shared_ptr<int>(y);
return 0;
};
---------------------------------------------
Here is the error under gdb:
Program received signal SIGSEGV, Segmentation fault.
0x080494cc in boost::shared_ptr<int>::dispose() (this=0x804b8c0)
at boost_1_23_0/boost/smart_ptr.hpp:250
250 void dispose() { if (--*pn == 0) { checked_delete(px); delete
pn; } }
The backtrace on a Linux box is
#0 0x080494cc in boost::shared_ptr<int>::dispose() (this=0x804b8c0)
at boost_1_23_0/boost/smart_ptr.hpp:250
#1 0x08049521 in boost::shared_ptr<int>::share(int*, long*)
(this=0x804b8c0,
rpx=0x804c2c8, rpn=0x804c2d8) at
boost_1_23_0/boost/smart_ptr.hpp:256
#2 0x0804924b in
boost::shared_ptr<int>::operator=(boost::shared_ptr<int> const&)
(this=0x804b8c0, r=@0xbffff664) at boost_1_23_0/boost/smart_ptr.hpp:202
#3 0x08048f10 in main () at pippo.C:10
#4 0x400bca8e in __libc_start_main (main=0x8048e60 <main>, argc=1,
argv=0xbffff6f4, init=0x8048bf0 <_init>, fini=0x8049e50 <_fini>,
rtld_fini=0x4000aa20 <_dl_fini>, stack_end=0xbffff6ec)
at ../sysdeps/generic/libc-start.c:92
where the contents of this=0x804b8c0 is:
(gdb) p *this
$2 = {px = 0x0, pn = 0x0}
If I uncomment the line
//a.resize(8);
then the program works fine.
Thanks in advance for your help/suggestions,
Marco Morandini
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk