Warning C6271

Extra argument passed to 'function'

Remarks

This warning indicates that extra arguments are being provided beyond the ones specified by the format string. By itself, this defect doesn't have any visible effect although it indicates that the programmer's intent isn't reflected in the code.

Code analysis name: EXTRA_ARGUMENT_TO_FORMAT_FUNCTION

Example

The following sample code generates this warning:

#include <stdio.h>

void f()
{
   char buff[5];

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

To correct this warning, remove the unused parameter or modify the format string to take it into account:

#include <stdio.h>

void f()
{
   char buff[5];

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

The following sample code calls the safe string manipulation function, sprintf_s, to correct this warning:

#include <stdio.h>

void f()
{
   char buff[5];

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

See also

Format specification syntax: printf and wprintf functions
sprintf, _sprintf_l, swprintf, _swprintf_l, __swprintf_l
sprintf_s, _sprintf_s_l, swprintf_s, _swprintf_s_l
C4474