/******************************************************
** smash the stack:
** This is intentionally terrible code to be use as an
** example while debugging issues
**
** To see what is happening on inside, check out
** https://docs.wokwi.com/gdb-debugging
******************************************************/
#include <stdio.h>
#include "pico/stdlib.h"
#define MAX_NAME_LENGTH 10
// enter more than 10 characters to cause problems
void unbounded_fill_from_input(char* name)
{
int i = 0;
char ch;
ch = getchar();
while (ch != '\n') { // wait for new line
name[i] = ch; i++;
ch = getchar();
}
name[i] = NULL; // NULL terminate string
}
void overflow_the_stack(void)
{
char name[MAX_NAME_LENGTH];
printf("Hello! Tell me your name: ");
unbounded_fill_from_input(name);
printf("Hello %s\r\n", name);
}
int main() {
stdio_init_all();
while (true) {
overflow_the_stack();
sleep_ms(250);
}
}