Warning C28308

The format list argument position specified by the annotation is incorrect.

Remarks

This warning indicates a _*_format_strings_param(position) SAL annotation is specifying an invalid position for the first parameter to the format string. The annotation helps the checker verify printf style formatting strings passed to the function. Other format string validity checks that rely on this annotation won't run as a result of this warning.

The _*_format_strings_param(position) SAL annotation is attached to the formatting string argument. position must be in one of these forms:

  • An identifier, which is taken as the first argument to the format string. When the identifier isn't the name of a parameter to the function, a warning is emitted.
  • A positive integer offset relative to the format-string parameter where 1 is the next parameter. When the offset is out of bounds for the parameters, a warning is emitted.
  • The value 0, which is interpreted as the ... parameter. When the function isn't variadic, a warning is emitted.

One limitation of this check, is that it's run at the function call site and not at the declaration. This limitation is a side effect of the lazy evaluation of SAL annotations.

Examples

In this example, there's a specialized function for logging coordinates. The params annotation specifies the ... parameter, which doesn't exist.

void LogCoordinate(_Printf_format_string_params_(0) _In_ char *format, int x, int y);

void func(int x, int y)
{
    LogCoordinate("(%d, %d)", x, y);
}

This issue is fixed by changing the annotated position to x or 1. To determine the correct value for your code, check the behavior of the called function.

void LogCoordinate(_Printf_format_string_params_(1) _In_ char *format, int x, int y);

void func(int x, int y)
{
    LogCoordinate("(%d, %d)", x, y);
}

See also

Annotating function parameters and return values