Edit

Share via


Warning C6066

Non-pointer passed as parameter(number) when pointer is required in call to 'function'.

Remarks

This warning indicates that the format string specifies that a pointer is required, but a non-pointer is being passed. A pointer is required, for example, when you use a %n or %p specification for printf, or a %d for scanf. This defect is likely to cause a crash or corruption of some form.

Code analysis name: NON_POINTER_ARGUMENT_TO_FORMAT_FUNCTION

Example

The following code generates this warning:

#include <stdio.h>
#define MAX 30
void f( )
{
  char buff[MAX];
  sprintf( buff, "%s %p %d", "Hello, World!", 1, MAX ); //warning C6066
  // code ...
}

void g( int i )
{
   int result = scanf( "%d", i ); // warning C6066
   // code ...
}

To correct this warning, the following code passes correct parameters to the sprintf and scanf functions:

#include <stdio.h>
#define MAX 30

void f( )
{
   char buff[MAX];
   sprintf( buff, "%s %p %d", "Hello, World!", buff, MAX ); // pass buff
   // code ...
}
void g( int i )
{
   int result = scanf( "%d", &i ); // pass the address of i
   // code ...
}

The following code uses safe string manipulation functions sprintf_s and scanf_s to correct this warning:

void f( )
{
   char buff[MAX];
   sprintf_s( buff, sizeof(buff), "%s %p %d", "Hello, World!", buff, MAX );
   // code ...
}
void g( int i )
{
   int result = scanf_s( "%d", &i );
   // code ...
}

This warning is typically reported because an integer has been used for a %p format instead of a pointer. Using an integer in this instance isn't portable to 64-bit computers.

See also

Format specification syntax: printf and wprintf functions
sprintf_s, _sprintf_s_l, swprintf_s, _swprintf_s_l
scanf_s, _scanf_s_l, wscanf_s, _wscanf_s_l
C4313
C4477