crashes due to the wrong way using aligned_storage.
Steps to reproduce:
1. Start a consumer
channel.consume(queue, tag).onMessage(msgCallback)
2. Send a message to the consumer
3. The program crashes
Environment:
Windows 7 / VS2010
The reason:
The Windows prompted to memory corruption, I found some strange phenomenon
about stack_ptr<Message>, such as:
1.sizeof(stack_ptr<Message>) is equal to 2
2.stack_ptr._initialized becomes true after construct() called (actually,
it never has been assigned true, please see [1])
Finally I found that the root cause was stack_ptr._data, we directly used
aligned_storage rather than aligned_storage::type[2] as the type of _data.
so the _data was just an empty struct, and subsequent operations were
performed in illegal memory. It eventually led to the crash.
This patch we fixed the bug and add "_initialized = true" at the end of the
method stack_ptr::construct().
[1] https://github.com/CopernicaMarketingSoftware/AMQP-CPP/blob/master/include/stack_ptr.h#L83
[2] http://www.cplusplus.com/reference/type_traits/aligned_storage/
env:
```
OS: Centos6.5 Linux 2.6.32-431.el6.i686
gcc: 4.8.2
```
make error:
```
g++ -Wall -c -I. -std=c++11 -g -fpic -o tcpconnection.o tcpconnection.cpp
In file included from tcpconnected.h:19:0,
from tcpresolver.h:22,
from tcpconnection.cpp:14:
tcpbuffer.h: In member function ‘ssize_t AMQP::TcpBuffer::receivefrom(int)’:
tcpbuffer.h:406:66: error: no matching function for call to ‘max(long int, int&)’
if (result < available) buffer.resize(std::max(0L, result));
^
tcpbuffer.h:406:66: note: candidates are:
In file included from /usr/local/include/c++/4.8.2/bits/char_traits.h:39:0,
from /usr/local/include/c++/4.8.2/string:40,
from includes.h:14,
from tcpconnection.cpp:13:
/usr/local/include/c++/4.8.2/bits/stl_algobase.h:216:5: note: template<class _Tp> const _Tp& std::max(const _Tp&, const _Tp&)
max(const _Tp& __a, const _Tp& __b)
^
/usr/local/include/c++/4.8.2/bits/stl_algobase.h:216:5: note: template argument deduction/substitution failed:
In file included from tcpconnected.h:19:0,
from tcpresolver.h:22,
from tcpconnection.cpp:14:
tcpbuffer.h:406:66: note: deduced conflicting types for parameter ‘const _Tp’ (‘long int’ and ‘int’)
if (result < available) buffer.resize(std::max(0L, result));
^
...
```