C6302
warning C6302: format string mismatch: character string passed as parameter <number> when wide character string is required in call to <function>
This warning indicates that the format string specifies that a wide character string is required. However, a character string is being passed. This defect is likely to cause a crash or a corruption of some form.
Example
The following sample code generates this warning because a character string is passed to wprintf function:
#include<stdio.h>
void f()
{
char buff[5] = "hi";
wprintf(L"%s", buff);
}
The following sample code uses %hs to specify a single-byte character string with wprintf function:
#include<stdio.h>
void f()
{
char buff[5] = "hi";
wprintf(L"%hs", buff);
}
The following sample code uses safe string manipulation function wprintf_s to correct this warning:
#include<stdio.h>
void f()
{
char buff[5] = "hi";
wprintf_s(L"%hs", buff);
}