printf (with %n) 引发致命错误. [英] printf (with %n) raises fatal error.

查看:76
本文介绍了printf (with %n) 引发致命错误.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我尝试运行的一个非常简单的代码:

Here is a very simple code that I'm trying to run:

#include <stdio.h>

void main()
{
    int x;
    printf( "TEST%n", &x );
}

我希望 x 变为等于 4,而不是我收到致命错误.

I expect x to become equal 4 instead I'm getting fatal error.

我使用 Visual Studio 2008 和 Windows XP.

I use Visual Studio 2008 and Windows XP.

在执行过程中,我看到窗口说 Microsoft Visual Studio C 运行时库检测到一个致命错误..."
然后调试器使用 _CRT_DEBUGGER_HOOK 函数打开 dbgook.c 文件.

During execution I get window saying "Microsoft Visual Studio C Runtime Library has detected a fatal error..."
Then debugger opens up dbghook.c file with _CRT_DEBUGGER_HOOK function.

请帮助我理解我做错了什么?

Please help me understand what am I doing wrong?

推荐答案

来自 MSDN 格式类型页面:

安全说明 %n 格式本质上是不安全的,默认情况下是禁用的;如果在格式字符串中遇到 %n,则调用无效参数处理程序,如 参数验证.要启用 %n 支持,请参阅 _set_printf_count_output.

Security Note The %n format is inherently insecure and is disabled by default; if %n is encountered in a format string, the invalid parameter handler is invoked as described in Parameter Validation. To enable %n support, see _set_printf_count_output.

这篇关于printf (with %n) 引发致命错误.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆