_stprintf & _sntprintf 过期了怎么办?

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列表如下:

Strsafe.h functionReplaces
StringCchCat
StringCchCatEx
strcat, wcscat
StringCchCatN
StringCchCatNEx
strncat
StringCchCopy
StringCchCopyEx
strcpy, wcscpy
StringCchCopyN
StringCchCopyNEx
strncpy
StringCchGets
StringCchGetsEx
gets, _getws
StringCchPrintf
StringCchPrintfEx
sprintf, swprintf, <?XML:NAMESPACE PREFIX = MSHelp NS = "http://msdn.microsoft.com/mshelp" />, _snprintf, _snwprintf
StringCchVPrintf
StringCchVPrintfEx
vsprintf, vswprintf, _vsnprintf, _vsnwprintf
StringCchLengthstrlen
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值