Boost logo

Boost :

Subject: Re: [boost] [any] Infinite loop in boost::any in boost release 1.54.0 using Visual C++ 2010
From: MANTOSH KUMAR (mantosh4u_at_[hidden])
Date: 2013-10-08 02:05:40


Hi,

Just checked the boost/any.hpp code and found that there could be
possibility of infinite loop in the following:

Code Snippet From boost/any.hpp
=========================

 any(const any & other)
          : content(other.content ? other.content->clone() : 0)
 {
 }

// Move constructor
 any(any&& other) BOOST_NOEXCEPT
       : content(other.content)
{
     other.content = 0;
}

 virtual placeholder * clone() const
 {
     return new holder(held);
 }

Test Code Snippet
===============
const boost::any getBoolVal()
{
    return false;
}

At this point, when the function getBoolVal() is returns, it would call "copy
constructor" which would call the "move constructor". Now "move constructor"
would assign the "content" value to 0. Due to this, copy constructor wouldcall
"content->clone()" as "content" value is set to 0 by "move constructor".

Now "clone()" function is calling "new" operator which internally calls
"malloc" to get the memory from the heap. These functions could be seen in
the top in the given call stacks.

This seems to be resulting into infinite loop. This is my personal opinion
and it could be wrong. Lets wait the experts analysis on this to
understand it completely.

Thanks,
Mantosh Kumar

On Tue, Oct 8, 2013 at 10:33 AM, Bo Peng <elapsing_at_[hidden]> wrote:

> This very simple code:
>
> #include <boost/any.hpp>
> #include <string>
>
> const boost::any getBoolVal()
> {
> return false;
> }
>
> int main()
> {
> boost::any vals[] = {1.0, std::string("1m"), getBoolVal()};
> }
>
> When built using Visual C++ 2010, it will run into a infinite loop:
> ntdll.dll!_RtlAllocateHeap_at_12() + 0x8 bytes
> ntdll.dll!_RtlDebugAllocateHeap_at_12() + 0x86 bytes
> ntdll.dll!@RtlpAllocateHeap_at_20() + 0x1108a bytes
> ntdll.dll!_RtlAllocateHeap_at_12() - 0x28d8a bytes
> msvcr100d.dll!_heap_alloc_base(unsigned int size=44) Line 55 C
> msvcr100d.dll!_heap_alloc_dbg_impl(unsigned int nSize=8, int nBlockUse=1,
> const char * szFileName=0x00000000, int nLine=0, int *
> errno_tmp=0x002a3280) Line 431 + 0x9 bytes C++
> msvcr100d.dll!_nh_malloc_dbg_impl(unsigned int nSize=8, int nhFlag=0, int
> nBlockUse=1, const char * szFileName=0x00000000, int nLine=0, int *
> errno_tmp=0x002a3280) Line 239 + 0x19 bytes C++
> msvcr100d.dll!_nh_malloc_dbg(unsigned int nSize=8, int nhFlag=0, int
> nBlockUse=1, const char * szFileName=0x00000000, int nLine=0) Line 302 +
> 0x1d bytes C++
> msvcr100d.dll!malloc(unsigned int nSize=8) Line 56 + 0x15 bytes C++
> msvcr100d.dll!operator new(unsigned int size=8) Line 59 + 0x9 bytes C++
> test.exe!boost::any::any<boost::any const >(const boost::any &&
> value={...}, void * __formal=0x00000000) Line 73 + 0x49 bytes C++
> test.exe!boost::any::holder<boost::any const >::holder<boost::any const
> >(const boost::any && value={...}) Line 177 C++
> ...
> test.exe!boost::any::any<boost::any const >(const boost::any &&
> value={...}, void * __formal=0x00000000) Line 73 + 0x71 bytes C++
> test.exe!boost::any::holder<boost::any const >::holder<boost::any const
> >(const boost::any && value={...}) Line 177 C++
> test.exe!boost::any::any<boost::any const >(const boost::any &&
> value={...}, void * __formal=0x00000000) Line 73 + 0x71 bytes C++
> test.exe!boost::any::holder<boost::any const >::holder<boost::any const
> >(const boost::any && value={...}) Line 177 C++
> test.exe!boost::any::any<boost::any const >(const boost::any &&
> value={...}, void * __formal=0x00000000) Line 73 + 0x71 bytes C++
> test.exe!boost::any::holder<boost::any const >::holder<boost::any const
> >(const boost::any && value={...}) Line 177 C++
> > test.exe!boost::any::any<boost::any const >(const boost::any &&
> value={...}, void * __formal=0x00000000) Line 73 + 0x71 bytes C++
> test.exe!main() Line 11 + 0x9c bytes C++
>
> Sorry I don't know enough of the c++ standard to figure out whether it is
> because of Visual C++ or it is because of boost. But I think it is worth to
> raise it to the experts out here.
>
> Thanks
> Bo
>
> ----
>
> http://www.pengbo.me
>
> _______________________________________________
> Unsubscribe & other changes:
> http://lists.boost.org/mailman/listinfo.cgi/boost
>


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