Update:
微软网站上面两篇关于软件安全的文章提到SafeCRT liberaries, 在VS2005开始提供,可以试试:
http://download.microsoft.com/download/1/1/d/11d125ba-d95c-480a-8a99-4700089a93e9/DSK302.ppt
http://download.microsoft.com/download/2/3/2/232d5429-e8c4-40da-9d90-bd33bab01e6f/DEV380-linhua.pdf
这两篇文章本身也是不错的资料。
----------------------------------------------------------------------------------------
今天做了一个小测试程序,结果发现_stprintf过期了,再试试发现_sntprintf也过期了
error C4995: '_sntprintf': name was marked as #pragma deprecated
error C4995: '_snwprintf': name was marked as #pragma deprecated
真tmd的晕,过期了也这么霸道,根本就不告诉你过期了怎么办,
其实编译器只要给个链接到新的函数上面可以节省程序员好多时间
暗骂编译器n遍以后,上google搜了一下,发现了一个基本上对应于_sntprintf的函数:StringCchPrintf
HRESULT StringCchPrintf(
LPTSTR pszDest,
size_t cchDest,
LPCTSTR pszFormat,
...
);
该函数返回如下结果以证明其清白(安全)
S_OK
There was sufficient space for the result to be copied to pszDest without truncation, and the buffer is null-terminated.
STRSAFE_E_INVALID_PARAMETER
The value in cbDest is 0 or larger than STRSAFE_MAX_CCH * sizeof(TCHAR).
STRSAFE_E_INSUFFICIENT_BUFFER
The copy operation failed due to insufficient buffer space. The destination buffer contains a truncated, null-terminated version of the intended
result. Where truncation is acceptable, this is not necessarily a failure condition.
不爽的话也可以试试StringCbPrintf,差不多,区别在于byte & TCHAR
顺便看了一下该头文件(Strsafe.h)中的其他函数,copy列表如下: