TE
科技回声
首页
24小时热榜
最新
最佳
问答
展示
工作
中文
GitHub
Twitter
首页
Strncpy like a boss
4 点
作者
xfactor973
超过 10 年前
2 条评论
tlb
超过 10 年前
Collapse
Please use strlcpy [1] instead.<p>[1] <a href="http://www.unix.com/man-page/freebsd/3/strlcpy/" rel="nofollow">http://www.unix.com/man-page/freebsd/3/strlcpy/</a>
评论 #8311464 未加载
nly
超过 10 年前
Putting aside the fact that using sizeof is risky in itself, i'd argue the default form should be<p><pre><code> strncpy (buffer, "abcd", sizeof(buffer)); assert (!buffer[sizeof(buffer) - 1]);</code></pre>