C6271

更新:2007 年 11 月

警告 C6271:向 <function> 传递了额外参数: 参数 <number> 未由格式字符串使用

此警告意味着提供了格式字符串所指定参数以外的其他参数。尽管此缺陷意味着代码没有反映出程序员的目的,但是它本身将不会有任何可见的影响。

示例

下面的代码示例生成此警告:

#include <stdio.h>
#include <string.h>

void f()
{
   char buff[5];

   sprintf(buff,"%d",1,2); 
}

若要更正此警告,请使用下面的代码示例:

#include <stdio.h>
#include <string.h>

void f()
{
   char buff[5];

   sprintf(buff,"%d, %d",1,2);
}

下面的代码示例调用安全的字符串操作函数 sprintf_s 来更正此警告:

#include <stdio.h>
#include <string.h>

void f()
{
   char buff[5];

   sprintf_s( buff, 5,"%s %d", 1,2 ); //safe version
}

请参见

参考

sprintf, _sprintf_l, swprintf, _swprintf_l, __swprintf_l