4
#include <sigc++/sigc++.h>
9
static void Foo(sigc::trackable&) {}
13
sigc::trackable *t = new sigc::trackable();
14
std::cout << "sigc::trackable instance at " << t << std::endl;
15
sigc::slot<void> foo = sigc::bind(sigc::ptr_fun(Foo), sigc::ref(*t));
16
// This invalidates foo.
19
// Try to crash if the invalid slot parameter is used by libsigc++,
20
// and get a debugger backtrace at the point that it happens.
22
// Comment this out to get a meaningful backtrace from valgrind.
24
// Try to pollute the memory previously occupied by the sigc::trackable
25
// instance. The hope is that with a regular memory allocator (i.e. not
26
// valgrind), we end up with buffer == (void *)t.
27
void *buffer = malloc(sizeof(sigc::trackable));
28
memset(buffer, 0xFF, sizeof(sigc::trackable));
29
std::cout << " Polluted buffer at " << buffer << std::endl;
31
// Now copy foo: up to libsigc++ version 2.0.11, the copy constructor fails
32
// because the pointer value it dereferences does not point to a
33
// sigc::trackable anymore, it now points to a polluted buffer.
34
sigc::slot<void> bar = foo;