Skip to content

Latest commit

 

History

History
64 lines (45 loc) · 1.69 KB

c6271.md

File metadata and controls

64 lines (45 loc) · 1.69 KB
description title ms.date f1_keywords helpviewer_keywords
Learn more about: Warning C6271
Warning C6271
3/06/2023
C6271
EXTRA_ARGUMENT_TO_FORMAT_FUNCTION
__WARNING_EXTRA_ARGUMENT_TO_FORMAT_FUNCTION
C6271

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