// 02_stack_overflow_nonexample.c (Wokwi-ready)
// Demonstrates overflowing a small stack buffer by passing a larger size to snprintf.
#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
static void tiny_stack_task(void *arg) {
char buf[2];
int x;
printf("[OF] about to write up to 64 bytes into an 2-byte buffer...\n");
// Overflow: snprintf instructed to write up to 64 bytes into 8.
// Some systems may still appear to "work", others may crash.
snprintf(buf, 64, "temp=%d", 1234567890);
printf("[OF] buf now claims: \"%s\" (undefined behavior)\n", buf);
vTaskDelete(NULL);
}
void app_main(void) {
setvbuf(stdout, NULL, _IONBF, 0);
printf("[OF] starting non-example\n");
xTaskCreate(tiny_stack_task, "tiny", 2048, NULL, 5, NULL);
for (;;) vTaskDelay(pdMS_TO_TICKS(1000));
}