cybersecurity · intermediate · ~15 min

strlcat-style append

Append without overflowing.

Challenge

Implement int safe_cat(char *dst, int dstsz, const char *src) appending src to dst without exceeding dstsz-1 bytes, always NUL-terminating. Return 0 if it fit, -1 if truncated.

Starter code

#include <string.h>

int safe_cat(char *dst, int dstsz, const char *src) {
    /* TODO */
    return -1;
}

Solve this exercise in the browser editor — compile and run against the test harness, no setup required.