HeapCrash / Challenges / Report task stack overflow

Report task stack overflow

A reporting task (FreeRTOSConfig.h excerpt at the top) formats readings and checks a config command's nesting depth. It worked until someone switched the output to floating point. Now the device occasionally reboots with corrupted task names in the crash log, and one malformed command from the test team kills it every time.

The code

Embedded C for Cortex-M. It compiles. There are 3 real bugs in it: the kind that pass a bench test and fail in the field.

/* FreeRTOSConfig.h */
#define configCHECK_FOR_STACK_OVERFLOW 0

/* report.c */

static int depth_of(const char *s)
{
    if (*s != '[') return 0;
    return 1 + depth_of(s + 1);
}

void report_task(void *p)
{
    char line[256];
    for (;;) {
        float t = read_temp();
        snprintf(line, sizeof line, "T=%.2f C nest=%d", (double)t, depth_of(cmd_buf));
        uart_puts(line);
        vTaskDelay(pdMS_TO_TICKS(1000));
    }
}

void app_init(void)
{
    xTaskCreate(report_task, "report", 128, NULL, 2, NULL);
}

What an interviewer expects

The bugs, reference fixes and the follow-up question are in the practice app, after you've tried it.

Companies that test this

Matched on the skills each company's embedded roles emphasise.

Related challenges

Flag the lines, say what breaks, then fix it and build it with clang in your browser.

Find the bugs