Boost logo

Boost Users :

Subject: Re: [Boost-users] shared_ptr question
From: Peter Dimov (pdimov_at_[hidden])
Date: 2010-05-18 13:27:00


David Michael Bond wrote:
...
> I looked into it more and it seems if I comment out the memcpy in the
> get_ether_header function I do not get the segfault.
>
> ether_header Frame::get_ether_header( ) {
> ether_header ret ;
> memcpy( &ret, this->bytes.get(), this->size ) ;
> return ret ;
> }
>
> Its fine to return that stack var right there right? That should just copy
> the memory into the return value for the stack?

It's fine to return a stack variable, but it may not be fine to memcpy into
it, depending on how ether_header is defined and whether this->size may
exceed sizeof(ether_header).

To investigate further, you might want to look at the stack backtrace when
the segfault occurs. Your shared_ptr use seems fine, so it's probably ~Frame
that is crashing (unless there is memory damage).


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net