HeapCrash / Challenges / Logging through a queue

Logging through a queue

Any task can call log_info. A logger task prints messages over UART. The log is full of garbage characters.

RTOSWarm-up3 bugs~4 minRTOS and concurrency

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.

typedef struct {
    char    text[48];
    uint8_t level;
} log_msg_t;

QueueHandle_t log_q;   /* item size: sizeof(log_msg_t *) */

void log_info(const char *s)
{
    log_msg_t m;
    strncpy(m.text, s, sizeof m.text);
    m.level = 1;
    log_msg_t *pm = &m;
    xQueueSend(log_q, &pm, 0);
}

void log_task(void *p)
{
    log_msg_t *pm;
    for (;;) {
        xQueueReceive(log_q, &pm, portMAX_DELAY);
        uart_puts(pm->text);
    }
}

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