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.
extern uint32_t __app_start, __app_end; /* linker-script symbols */
extern const uint32_t __app_crc; /* CRC word stored right after the image */
static uint32_t crc32(const uint8_t *p, uint32_t n)
{
uint32_t c = 0;
while (n--) {
c ^= *p++;
for (int k = 0; k < 8; k++) c = (c >> 1) ^ (0xEDB88320u & (0u - (c & 1u)));
}
return c;
}
bool flash_selftest(void)
{
uint32_t len = __app_end - __app_start;
uint32_t crc = crc32((const uint8_t *)__app_start, len);
if (crc != __app_crc) {
log_warn("flash CRC mismatch");
}
return true;
}What an interviewer expects
- Point to each line you'd stop in a code review.
- Say what actually breaks: the failure mode, not just the rule it violates.
- Fix it, then defend the fix when asked the follow-up.
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