Struct fields uninitialized
Review this C function that reports a parsed header.
What a strong answer looks like
Separate real bugs from style. Rank issues by severity, point at the root cause rather than the symptom, and suggest a concrete fix, specific and kind.
0:00 of about 20 min
Mark a line and say what kind of problem it is.0 findings
1#include <stdio.h>
2
3struct Header { int version; int flags; int length; };
4
5struct Header parse(const unsigned char *buf, size_t n) {
6 struct Header h;
7 h.version = buf[0];
8 if (n > 4) {
9 h.length = (buf[1] << 8) | buf[2];
10 }
11 return h;
12}
13
14int main(void) {
15 unsigned char data[2] = {1, 0};
16 struct Header h = parse(data, sizeof data);
17 printf("flags=%d length=%d\n", h.flags, h.length);
18}
Which questions mattered is sealed until you submit. Telling you now would just be handing over the edge cases.
Run or narrate your approach, then ask the coach.