I would argue that copying <i>more</i> bytes (as demonstrated) is correct behaviour:<p>(1.) The function is supposed to append a string to another, not paste a byte range into another one, leaving extra bytes at the end untouched. Thus the functional result in the test code is correct (i.e. contains the concatenated string with for the usual definition of NUL-terminated strings.)<p>(2.) The strncat man page (and similarly the C99 standard) says: &quot;[...] the size of dest must be at least strlen(dest)+n+1.&quot; It does not specify what happens to unused bytes at the end. It would be incorrect if the function would ever touch more than `strlen(dest)+n+1` bytes in dest, but it doesn&#x27;t. Supplying a proper value for n in the code (e.g. `strlen(s2)`) shows that it wouldn&#x27;t overrun the buffer.<p>Thus supplying SIZE_MAX for `n` would be a bad idea (because the function could overwrite random memory locations) and would probably be incorrect in most cases (e.g. on amd64 with SIZE_MAX=2^64-1 it would only be correct for the null pointer.)<p>Copying <i>less</i> would obviously be incorrect. I couldn&#x27;t reproduce that though. (The <i>more</i> case even appears on Ubuntu with eglibc on both x86 and amd64.)<p>Also, this is probably still a bug and not the anticipated behaviour. (As in: whoever wrote that didn&#x27;t think of those cases and the overflow happens by mistake.)