Skip to content

Instantly share code, notes, and snippets.

@snoopspy
Last active August 29, 2015 14:22
Show Gist options
  • Save snoopspy/e3e197157c478c6fea4e to your computer and use it in GitHub Desktop.
Save snoopspy/e3e197157c478c6fea4e to your computer and use it in GitHub Desktop.
#include <cstring>
#include <iostream>
char buf[256];
size_t idx = 0;
void *malloc(size_t size) {
void* res = &buf[idx];
memset(res, 0xFF, size);
idx += size;
return res;
}
void free(void* ptr) {
(void)ptr;
}
int main() {
{
int* i = new int;
std::cout << *i << std::endl;
delete i;
}
{
int* i = new int();
std::cout << *i << std::endl;
delete i;
}
}
@snoopspy
Copy link
Author

[environment]
os : 14.04.1-Ubuntu 64 bit
compiler : g++ (Ubuntu 4.8.2-19ubuntu1) 4.8.2
build : g++ -std=c++11 test.cpp

[result]
-1
0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment