读读文档就知道了
The strncpy function copies the initial count characters of strSource to strDest and returns strDest. If count is less than or equal to the length of strSource, a null character isn't appended automatically to the copied string. If count is greater than the length of strSource, the destination string is padded with null characters up to length count.
strncpy 不是最多复制 count 个字符,而是 *一定* 复制 count 个字符。
【 在 timeleap 的大作中提到: 】
: char *strncpy(char *dest, const char *src, size_t n);
: 项目中遇到一个问题,就是代码bug导致n设定的比dest实际长度大了一些
: 然后发生了越界写入,把其他的数据给写坏了
: ...................
--
FROM 120.194.8.*