Code RoomGreeting buffer overflows
MediumPrep Room Coding #2012

Greeting buffer overflows

Code reviewAlgorithms & data structuresMid–Senior~18 min

Review this C function that builds a greeting string on the heap.

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 18 min
Mark a line and say what kind of problem it is.0 findings
1char *greet(const char *name) {
2 size_t n = strlen(name);
3 char *out = malloc(n); // room for the name
4 sprintf(out, "Hi, %s!", name); // write greeting
5 return out;
6}
Which questions mattered is sealed until you submit. Telling you now would just be handing over the edge cases.