Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
None
-
None
-
None
-
All
Description
The program below aborts due to deallocating the external buffer extbuf.
test.cpp:
------------------
#include <sstream> // for stringbuf
#include <memory> // for allocator
#include <cassert> // for assert()
char extbuf [3];
struct MyAlloc : std::allocator <char>
{
pointer allocate (size_type __n, std::allocator<void>::const_pointer = 0)
void deallocate (pointer __p, size_type)
{ assert (extbuf != __p); delete [] __p; }};
int main ()
{
std::basic_stringbuf <char, std::char_traits <char>, MyAlloc> sbuf;
sbuf.pubsetbuf (extbuf, sizeof (extbuf));
const char* str = "abcdef";
sbuf.str (str);
assert (sbuf.str () == str);
return 0;
}
------------------
The test output:
------------------
test: test.cpp:16: void MyAlloc::deallocate(char*, unsigned int): Assertion `extbuf != __p' failed.
Aborted
------------------