Does strncat() always null terminate?
It always null-terminate.
Quoting C11
, chapter §7.24.3.2, (emphasis mine)
The
strncat
function appends not more thann
characters (a null character and characters that follow it are not appended) from the array pointed to bys2
to the end of the string pointed to bys1
. The initial character ofs2
overwrites the null character at the end ofs1
. A terminating null character is always appended to the result.
and, the footnote
Thus, the maximum number of characters that can end up in the array pointed to by
s1
isstrlen(s1)+n+1
.