#define STACK_CANARY_VALUE 0xDEADBEEFchar _log_buffer[128];uint32_t _log_buffer_canary = STACK_CANARY_VALUE;void my_function(void) { // your code bla bla bla // This is where you should check the canary before using printf if (_log_buffer_canary != STACK_CANARY_VALUE) { // Stack corruption detected! // Handle the error prolly stop execution or trigger a watchdog } // Now it is safe hopefully to use printf vsnprintf(_log_buffer, sizeof(_log_buffer), "%d", some_variable);}