Boost logo

Boost :

Subject: Re: [boost] Weak pointer to object not managed by a shared_ptr
From: Mateusz Loskot (mateusz_at_[hidden])
Date: 2009-09-05 17:09:16


OvermindDL1 wrote:
> Bah, x1 exists on the stack, its memory is not free'd after its
> destructor is run, hence when you access get_i, it still return 7.

Yes, it's been perfectly clear for me.
Perhaps I used some shortcuts in my explanation.

> Try adding this right before that ->get_i call:
> char buf_on_stack[255]; // or however large X is, plus some for just in case...
> memset(&buf_on_stack, 255, size_of(buf_on_stack));
>
> Then notice that your get_i call does not return 7, rather it returns
> part of that array, which is filled with all 1's.

Just for records, it doesn't cause such effect for Visual C++ 9.0.
However, it doesn't change the fact of UB we've already discussed and
agreed.

Best regards,

-- 
Mateusz Loskot, http://mateusz.loskot.net
Charter Member of OSGeo, http://osgeo.org

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk