Our website uses cookies to enhance your browsing experience.
Accept
to the top
>
>
>
V3025. Incorrect format. Consider check…
menu mobile close menu
Analyzer diagnostics
General Analysis (C++)
General Analysis (C#)
General Analysis (Java)
Micro-Optimizations (C++)
Diagnosis of 64-bit errors (Viva64, C++)
Customer specific requests (C++)
MISRA errors
AUTOSAR errors
OWASP errors (C++)
OWASP errors (C#)
Problems related to code analyzer
Additional information
toggle menu Contents

V3025. Incorrect format. Consider checking the N format items of the 'Foo' function.

Nov 16 2015

The analyzer has detected a possible error related to use of formatting methods: String.Format, Console.WriteLine, Console.Write, etc. The format string does not correspond with actual arguments passed to the method.

Here are some simple examples:

Unused arguments.

int A = 10, B = 20;
double C = 30.0;
Console.WriteLine("{0} < {1}", A, B, C);

Format item {2} is not specified, so variable 'C' won't be used.

Possible correct versions of the code:

//Remove extra argument
Console.WriteLine("{0} < {1}", A, B);

//Fix format string
Console.WriteLine("{0} < {1} < {2}", A, B, C);

Number of arguments passed is less than expected.

int A = 10, B = 20;
double C = 30.0;
Console.WriteLine("{0} < {1} < {2}", A, B);
Console.WriteLine("{1} < {2}", A, B);

A much more dangerous situation occurs when a function receives fewer arguments than expected. This will raise a FormatException exception.

Possible correct versions of the code:

//Add missing argument
Console.WriteLine("{0} < {1} < {2}", A, B, C);

//Fix indices in format string
Console.WriteLine("{0} < {1}", A, B);

The analyzer doesn't output the warning given that:

  • The number of format items specified matches the number of arguments.
  • The format object is used a number of times:
int row = 10;
Console.WriteLine("Line: {0}; Index: {0}", row);

Here is an example of this bug in a real-life application:

var sql = string.Format(
  "SELECT {0} FROM (SELECT ROW_NUMBER() " +
  " OVER (ORDER BY {2}) AS Row, {0} FROM {3} {4}) AS Paged ",
  columns, pageSize, orderBy, TableName, where);

The function receives 5 formatting objects, but the 'pageSize' variable is not used as format item {1} is missing.

This diagnostic is classified as:

You can look at examples of errors detected by the V3025 diagnostic.

close form

Fill out the form in 2 simple steps below:

Your contact information:

Step 1
Congratulations! This is your promo code!

Desired license type:

Step 2
Team license
Enterprise license
** By clicking this button you agree to our Privacy Policy statement
close form
Request our prices
New License
License Renewal
--Select currency--
USD
EUR
* By clicking this button you agree to our Privacy Policy statement

close form
Free PVS‑Studio license for Microsoft MVP specialists
* By clicking this button you agree to our Privacy Policy statement

close form
To get the licence for your open-source project, please fill out this form
* By clicking this button you agree to our Privacy Policy statement

close form
I am interested to try it on the platforms:
* By clicking this button you agree to our Privacy Policy statement

close form
check circle
Message submitted.

Your message has been sent. We will email you at


If you do not see the email in your inbox, please check if it is filtered to one of the following folders:

  • Promotion
  • Updates
  • Spam