4 ms·
In addition to tlb's point, the article's description of strncat is not correct. > As with strcat(), the resulting string in dest is always null-terminated. >
by Hello71 8y ago
In addition to tlb's point, the article's description of strncat is not correct.
> As with strcat(), the resulting string in dest is always null-terminated.
> Therefore, the size of dest must be at least strlen(dest)+n+1.
- jwilk 8y agoThey wrote: // XXX: after this buf may not be null-terminated strncat(buf, another_buffer, BUF_SIZE - strlen(buf)); This code is indeed bad, but not because the result won't be null-terminated, but because it's an off-by-one buffer overflow. Despite this misunderstanding, the proposed fix is correct: // OK: ensure buf is null-terminated after concatenation strncat(buf, another_buffer, BUF_SIZE - strlen(buf) - 1);