Beware of strncpy and strncat
Beware of the &quot;correct&quot; solutions proposed here.<p><pre><code>  &#x2F;&#x2F; OK: correctly copy src
  char dest[8];
  strncpy(dest, src, sizeof(dest) - 1);
</code></pre>
With a long src, it fails to null-terminate dest. dest[7] will be whatever the contents of uninitialized memory were, so reading dest as a string is likely to run past the end.<p>strlcpy has a better API, though sadly it&#x27;s not standard on Linux.