Skip to question
asic.fyi
DesignVerificationSystemVerilogFirmwareArchitectureInterviews
asic.fyi/Interview questions/Count errors in a build report

Hardware interview practice

Count errors in a build report

EasyFirmware & ValidationC++

A build tool returns a byte buffer containing newline-separated log records; the buffer is not NUL-terminated. Write the C++ parser that counts records beginning with ERROR: and WARNING:.

Try it in the question bankReason first. Then compare.

Keep this exact question selected while you check your answer and review the full solution.

Practice this question →
Starting point

Question code

struct Counts { size_t errors, warnings; };
int count_log(const char *p, size_t n, Counts *out);
Reviewed example

Work through one case

Input
A 20-byte buffer containing "ERROR: a\nWARNING: b\n".
Expected output
Return 0 with errors=1 and warnings=1.

Each newline-delimited record begins with one exact uppercase prefix, so the bounded parser increments each counter once without needing a NUL terminator.

What to cover

Requirements

  1. Require out; p may be NULL only when n=0. Invalid arguments return -1 and preserve *out.
  2. A record starts at byte zero or immediately after '\n' and ends before the next '\n' or at n.
  3. Count a record only when its first bytes exactly match uppercase ERROR: or WARNING:; leading spaces do not match.
  4. Treat '\r' as an ordinary byte except that a trailing '\r' before '\n' does not affect prefix matching; write *out once and return 0.
Continue practicing

Related questions

Firmware & ValidationZero matrix rows and columns in place→Firmware & ValidationBounded byte-string palindrome check→Firmware & ValidationBounded MMIO command driver→
asic.fyi · Learn silicon end to end.info@asic.fyi