Comment Comment by tlb Beware of the "correct" solutions proposed here. // OK: correctly copy src char dest[8]; strncpy(dest, src, sizeof(dest) - 1); 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.strlcpy has a better API, though sadly it's not standard on Linux. parent tlb 8 years ago
strlcpy has a better API, though sadly it's not standard on Linux.