c++ - wsprintf() 的安全版本?

标签 c++ windows msvcrt fortify crt

就像我们有 _stprintf 的安全版本,即 hp fortify bufferoverflow 的 stprintf_s 警告,那么我们可以使用什么来代替 wsprintf()?我试过 wsprintf_s,它不工作。

谁能解释一下 b/w _stprintfwsprintf 的区别?或者我们可以使用 stprintf_s 作为 wsprintf 的安全版本。

最佳答案

选项记录在 wsprintf 下:

Note Do not use. Consider using one of the following functions instead: StringCbPrintf, StringCbPrintfEx, StringCchPrintf, or StringCchPrintfEx. See Security Considerations.

如果您更愿意使用更类似于 wsprintf 的安全函数, 去 swprintf_s_snwprintf_s .

_stprintf是一个预处理器宏,它将调用映射到 ANSI 或 UNICODE 版本。映射表记录在 sprintf, _sprintf_l, swprintf, _swprintf_l, __swprintf_l :

<表类="s-表"> <头> TCHAR.H 例程 _UNICODE & _MBCS 未定义 _MBCS 定义 _UNICODE 定义 <正文> _stprintf sprintf sprintf _swprintf

_stprintf_s 的映射表:

<表类="s-表"> <头> TCHAR.H 例程 _UNICODE & _MBCS 未定义 _MBCS 定义 _UNICODE 定义 <正文> _stprintf_s sprintf_s sprintf_s swprintf_s

关于c++ - wsprintf() 的安全版本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33212449/

相关文章:

c# - C++ DLL LPCTSTR 到 C# 字符串

c++可执行程序的分布式计算

Android Eclipse 和为项目配置 NDK 工具链

windows - 在 Haskell 中,waitForProcess 在 Windows 的 cmd.exe 下阻止 Ctrl-C

windows - MinGW/MinGW64 链接和依赖于 `msvcrt.dll`

c++ - 如何访问 MsBuild 中 <Target> 节点外的项目元数据?

c++ - 如何比较两个不同大小的字符串

c++ - kde 固定按钮 API

c - 在 cmd 中打印和存储西类牙语字符(á、é、í、ñ...)

c - 寻求对 Visual Studio C 运行时库链接行为的更深入了解