Code RoomString copy buffer size
MediumPrep Room Coding #1791

String copy buffer size

Code reviewCode quality & reviewMid–Senior~20 min

Review this C string-copy helper.

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 <string.h>
2#include <stdlib.h>
3 
4char *dup_upper(const char *src) {
5 size_t len = strlen(src);
6 char *out = malloc(len); /* room for the chars */
7 for (size_t i = 0; i < len; i++) {
8 char c = src[i];
9 out[i] = (c >= 'a' && c <= 'z') ? c - 32 : c;
10 }
11 out[len] = '\0'; /* terminate */
12 return out;
13}
Which questions mattered is sealed until you submit. Telling you now would just be handing over the edge cases.