by defined · 9y ago · 0 comments
All it takes to avoid a missing NUL terminator is something like
#define safer_strncpy(dest, src, n) \
do { \
if (n > 0) \
strncpy(dest, src, n)[n - 1] = '\0'; \
} while (0)Use snprintf() or strncat(), as suggested by the article.