Skip to content

Instantly share code, notes, and snippets.

@KindDragon
Last active February 22, 2017 13:26
Show Gist options
  • Save KindDragon/898e494bf1f43b1a033e1e28ec608323 to your computer and use it in GitHub Desktop.
Save KindDragon/898e494bf1f43b1a033e1e28ec608323 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <cassert>
void dirty_stack()
{
unsigned char array_on_stack[256];
for (unsigned i = 0; i < sizeof(array_on_stack); ++i)
{
array_on_stack[i] = 0x11;
}
}
struct int_pair_struct
{
int first;
int second;
};
typedef int int_pair_struct::*ptr_to_member_type;
struct ptr_to_member_struct
{
ptr_to_member_type data;
};
class value_initializer_ptr_to_member_struct
{
public:
ptr_to_member_struct _ptr_to_member_struct;
// Default constructor. Tries to value-initialize its base subobject and all
// of its data.members.
value_initializer_ptr_to_member_struct()
:
_ptr_to_member_struct()
{}
};
int main()
{
dirty_stack();
auto s = value_initializer_ptr_to_member_struct();
if (s._ptr_to_member_struct.data == 0)
std::cout << "SUCCESS: s.data == 0";
else
std::cout << "FAILURE: s.data != 0";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment