Dela via


C6273

Warning 6273 - non-integer passed as parameter <number> when integer is required in call to <function>: if a pointer value is being passed, %p should be used

This warning indicates that the format string specifies an integer, for example, a %d, length or precedence specification for printf but a non-integer such as a float, string, or struct is being passed as a parameter. This defect is likely to result in incorrect output.

Example

The following code generates this warning because an integer is required instead of a float to sprintf function:

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

void f_defective()
{
  char buff[50];
  float f=1.5;
  
  sprintf(buff, "%d",f);
}

The following code uses an integer cast to correct this warning:

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

void f_corrected()
{
  char buff[50];
  float f=1.5;

  sprintf(buff,"%d",(int)f);
}

The following code uses safe string manipulation function, sprintf_s, to correct this warning:

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

void f_safe()
{
  char buff[50];
  float f=1.5;

  sprintf_s(buff,50,"%d",(int)f);
}

This warning is not applicable on Windows 9x and Windows NT version 4 because %p is not supported on these platforms.

See Also

Reference

sprintf, _sprintf_l, swprintf, _swprintf_l, __swprintf_l