摘要: 好多人已经知道利用strncpy替代strcpy来防止缓冲区越界。但是如果还要考虑运行效率的话,也许strlcpy是一个更好的方式。1. strcpy我们知道,strcpy 是依据 \0 作为结束判断的,如果 to 的空间不够,则会引起 buffer overflow。strcpy 常规的实现代码如下(来自 OpenBSD 3.9):char *strcpy(char *to, const char *from){ char *save = to; for (; (*to = *from) != '\0'; ++from, ++to); return(save);}但通常,我们的 from 都 阅读全文
posted @ 2010-12-30 20:58 Kane_BJ 阅读(402) 评论(0) 推荐(0) 编辑