Boost logo

Boost Users :

Subject: Re: [Boost-users] shared_ptr question
From: David Michael Bond (david.bond_at_[hidden])
Date: 2010-05-18 14:00:12


*sighs*
This has nothing to do with boost. I meant to have:
  memcpy( &ret, this->bytes.get(), sizeof(ether_header) ) ;

Thanks for point that out. It must have been over-writing part of a
shared_ptr on the stack.

Ah, well at least I feel good that my understanding of shared_ptrs isn't
wrong. :-)

Thanks everyone,
David

> -----Original Message-----
> From: boost-users-bounces_at_[hidden] [mailto:boost-users-
> bounces_at_[hidden]] On Behalf Of Peter Dimov
> Sent: Tuesday, May 18, 2010 1:27 PM
> To: boost-users_at_[hidden]
> Subject: Re: [Boost-users] shared_ptr question
>
> 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 mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users


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