CRT 9.0 vsprintf_s 对长格式字符串的参数验证
来自此处:
这些函数的版本 _s 和 _p 后缀是更安全的版本。这些版本验证了 格式化字符串并会生成 如果格式字符串不是,则异常 格式良好(例如,如果无效 使用格式化字符)。
我刚刚发现如果格式字符串大于输出缓冲区大小,则认为格式字符串格式不正确。有谁知道确认所有 *_s 打印功能的文档?
谢谢
From here:
The versions of these functions with
_s and _p suffixes are the more secure versions. These versions validate the
format strings and will generate an
exception if the format string is not
well formed (for example, if invalid
formatting characters are used).
I just discovered the format string is considered not well formed if it is larger than the output buffer size. Does anyone know of documentation that confirms this for all *_s print functions?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来默认行为是在超过输出缓冲区大小时抛出 CRT 错误,无论源如何。我预计如果超出输出缓冲区大小,输出将被静默截断。因此,如果格式字符串已经太长,则尝试填充它是没有意义的。
Looks like the default behavior is to throw the CRT error if output buffer size is exceeded, regardless of source. I expected the output to be silently truncated if the output buffer size is exceeded. Thus, there is no point in attempting to fill in the format string if it is too long already.