Skip to content

Latest commit

 

History

History
46 lines (34 loc) · 2.22 KB

c6065.md

File metadata and controls

46 lines (34 loc) · 2.22 KB
description title ms.date f1_keywords helpviewer_keywords
Learn more about: Warning C6065
Warning C6065
2/22/2023
C6065
MISSING_COUNTED_STRING_ARGUMENT_TO_FORMAT_FUNCTION
__MISSING_COUNTED_STRING_ARGUMENT_TO_FORMAT_FUNCTION
C6065

Warning C6065

warning C6065: Missing pointer to 'string type' argument to 'function' that corresponds to argument 'number'

Remarks

This warning indicates that there's a mismatch between the format specifiers in a string and the types of the associated parameters. The format specifier indicates that at least one of the mismatched arguments should be a pointer to a counted string such as UNICODE_STRING or ANSI_STRING but it not. This defect can cause crashes, buffer overflows, and potentially incorrect output.

To fix this warning, determine if the format specifier or the argument matches the intended behavior and modify the other to match. When modifying the format specifier for a counted string, it's recommended to explicitly use the size prefix such as %wZ or %hZ rather than %Z due to compatibility issues between C runtimes (CRT). For more information on CRT compatibility, see the %Z row in the Type field characters documentation.

Code analysis name: MISSING_COUNTED_STRING_ARGUMENT_TO_FORMAT_FUNCTION

Example

The following code generates this warning because the value passed to printf isn't a pointer:

int PrintDiagnostic(UNICODE_STRING u)
{
    printf("%wZ", u);
}

In this example, we fix the warning by changing the passed in parameter to be a pointer:

int PrintDiagnostic(UNICODE_STRING u)
{
    printf("%wZ", &u);
}

See also

format specification syntax: printf and wprintf functions
sprintf_s, _sprintf_s_l, swprintf_s, _swprintf_s_l
UNICODE_STRING
ANSI_STRING/_STRING
C4313