Skip to content

Instantly share code, notes, and snippets.

@meowmeowxw
Last active October 29, 2020 19:55
Show Gist options
  • Save meowmeowxw/d58c925fe84aeb95d075e8e511de8656 to your computer and use it in GitHub Desktop.
Save meowmeowxw/d58c925fe84aeb95d075e8e511de8656 to your computer and use it in GitHub Desktop.
Fill the heap of arduino
class Counter {
public:
int count;
Counter(int value){
count = value;
}
~Counter(){
// destructor
}
void inc(){
count++;
}
int getValue(){
return count;
}
};
void setup() {
Serial.begin(9600);
}
Counter *x;
void loop() {
int y;
x = new Counter(50);
if (x == 0) {
// No more space on the heap
Serial.println(*(int *)0); // -> 50
x->count += 2;
Serial.println(*(int *)0); // -> 102 , probably the precedent operation overwrite the value of the register R0/R1
delay(5000);
} else {
Serial.print((unsigned long)x, HEX);
Serial.print(String(" "));
Serial.print((unsigned long)&y, HEX);
Serial.print(String(" "));
Serial.println(*(int *)0);
delay(40);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment