strncpy documentation question

后端 未结 6 1620
傲寒
傲寒 2020-12-10 07:47

At the following regarding strncpy: http://www.cplusplus.com/reference/clibrary/cstring/strncpy/, it mentions the following:

No null-char

6条回答
  •  旧巷少年郎
    2020-12-10 08:34

    It means that only num bytes will be copied from the source buffer to the destination buffer; so if the source string length if upper or equal to num, the terminating NULL byte will not be copied, and the result will not have a NULL terminating byte, which is dangerous.

    It is recommended to use strlcpy instead.

提交回复
热议问题