To get a trial key
fill out the form below
Team License (a basic version)
Enterprise License (an extended version)
* By clicking this button you agree to our Privacy Policy statement

Request our prices
New License
License Renewal
--Select currency--
* By clicking this button you agree to our Privacy Policy statement

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

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

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

Message submitted.

Your message has been sent. We will email you at

If you haven't received our response, please do the following:
check your Spam/Junk folder and click the "Not Spam" button for our message.
This way, you won't miss messages from our team in the future.

PVS-Studio refers to error "Some d…

PVS-Studio refers to error "Some diagnostic messages may contain incorrect line number for file ..."

Aug 28 2009

Sometimes PVS-Studio code analyzer can refer to this error: "Some diagnostic messages may contain incorrect line number for file ...". It may occur when using Microsoft Visual Studio 2005 without Visual Studio Service Pack 1. It is an error and not a diagnostic warning. In this note we will tell you about this error and how to react to it.

Any code analyzer, including PVS-Studio, deals only with preprocessed files, i.e. those files where all the macros are defined and all the included files are arranged (#include). A preprocessed file contains information about particular locations where all the files have been placed. That is, preprocessed files contain information about the lines' numbers.

Preprocessing is executed in any case. But for a user this procedure is transparent. Sometimes the preprocessor is included into the code analyzer as part of it and sometimes (as in case of PVS-Studio) an external preprocessor is used. In PVS-Studio we use a preprocessor by Microsoft Visual Studio. For every C/C++ file being processed the analyzer launches the command line compiler cl.exe and generates a preprocessed file with "i" extension with its help.

There is an error in the preprocessor by Microsoft Visual Studio 2005. If you perform preprocessing from the command line (as in PVS-Studio) the information about the numbers of the lines gets wrong when a program contains multi-line macros. This may cause incorrect positioning of the code analyzer in a file. That is, the code analyzer will find a real problem but will refer to a wrong number of the line it is detected in.

Let's explain it by an example. We use assert in a simple code and the expression in parentheses is split into several lines. For example:

int _tmain(int argc, _TCHAR* argv[])
  int a = 0;
  int b = 1;
  size_t c = 2;
  assert(a ==
  a++;   // The analyzer refers to an error in this safe line.
  c = a; // Although the diagnostic warning should actually
         // refer to the line "c = a;".
  return 0;

As you can see in the comments, because of the multi-line assert the analyzer says that there is an error (and it is right) but refers to the line above the one which actually contains the error. Of course, it can mislead the user.

If we write the same code with assert in one line there will be no problem:

int _tmain(int argc, _TCHAR* argv[])
  int a = 0;
  int b = 1;
  size_t c = 2;
  assert (a == b);
  c = a; // The diagnostic warning refers to the right line.
  return 0;

This error occurs only when using PVS-Studio in Microsoft Visual Studio 2005 without the service pack Visual Studio Service Pack 1. This problem is absent in Visual Studio 2005 Service Pack1 as well as in elder versions (Visual Studio 2008 and higher). So, to solve this problem we recommend that you install Visual Studio 2005 Service Pack 1 on Visual Studio 2005. Then the code with multi-line macros will be correctly processed by PVS-Studio analyzer.

However, sometimes it is impossible to install Visual Studio 2005 Service Pack 1 due to some reasons. In this case PVS-Studio analyzer tries to detect this error in the file being processed. This is a heuristic mechanism and it cannot guarantee correct definition of diagnostic warnings' positioning in the program code. But if it understands that a particular file contains multi-line macros and there is a positioning error, you see the warning: "Some diagnostic messages may contain incorrect line number for file ...".

This mechanism works in the following way.

The analyzer opens the source C/C++ file and searches the last lexeme. It selects lexemes not shorter than three symbols to ignore the closing parentheses and so on. For example, for the next code the last lexeme is "return" operator:

01 #include "stdafx.h"
03 int foo(int a)
04 {
05   assert(a >= 0 &&
06          a <= 1000);
07   int b = a + 1;
08   return b;
09 }

Having found the last lexeme the analyzer identifies the number of the line it is located in. In this case it is line number 8. Further, the analyzer searches the last lexeme in the already preprocessed file. If the last lexemes do not coincide, a macro must have opened in the end of the file and the analyzer cannot understand if the lines are correct and ignores this situation. But it occurs rather rarely and nearly in all the cases the last lexemes in the source file and in the preprocessed file coincide. If it is so, the analyzer can identify the number of the line where the lexeme is situated in the preprocessed file.

So, we have the numbers of the lines containing the last lexeme in the source file and in the preprocessed file. If these numbers do not coincide there is a failure in line numbering during macros' opening. And in this case the analyzer warns the user about it with the warning "Some diagnostic messages may contain incorrect line number for file ...".

You should keep in mind that if a multi-line assert or any other multi-line macro will be situated in the file below all the dangerous code sections detected, all the numbers of the lines for the errors detected will be correct. And although the analyzer will show the warning "Some diagnostic messages may contain incorrect line number for file ...", it will not prevent you from analyzing the diagnostic warnings received.

Pay attention, that although it is not a fault of PVS-Studio analyzer itself, still it causes incorrect operation of the code analyzer. The best solution of the problem is installation of Microsoft Visual Studio 2005 Service Pack 1.

Popular related articles
How PVS-Studio Proved to Be More Attentive Than Three and a Half Programmers

Date: Oct 22 2018

Author: Andrey Karpov

Just like other static analyzers, PVS-Studio often produces false positives. What you are about to read is a short story where I'll tell you how PVS-Studio proved, just one more time, to be more atte…
The way static analyzers fight against false positives, and why they do it

Date: Mar 20 2017

Author: Andrey Karpov

In my previous article I wrote that I don't like the approach of evaluating the efficiency of static analyzers with the help of synthetic tests. In that article, I give the example of a code fragment…
Static analysis as part of the development process in Unreal Engine

Date: Jun 27 2017

Author: Andrey Karpov

Unreal Engine continues to develop as new code is added and previously written code is changed. What is the inevitable consequence of ongoing development in a project? The emergence of new bugs in th…
Characteristics of PVS-Studio Analyzer by the Example of EFL Core Libraries, 10-15% of False Positives

Date: Jul 31 2017

Author: Andrey Karpov

After I wrote quite a big article about the analysis of the Tizen OS code, I received a large number of questions concerning the percentage of false positives and the density of errors (how many erro…
Free PVS-Studio for those who develops open source projects

Date: Dec 22 2018

Author: Andrey Karpov

On the New 2019 year's eve, a PVS-Studio team decided to make a nice gift for all contributors of open-source projects hosted on GitHub, GitLab or Bitbucket. They are given free usage of PVS-Studio s…
PVS-Studio for Java

Date: Jan 17 2019

Author: Andrey Karpov

In the seventh version of the PVS-Studio static analyzer, we added support of the Java language. It's time for a brief story of how we've started making support of the Java language, how far we've co…
The Evil within the Comparison Functions

Date: May 19 2017

Author: Andrey Karpov

Perhaps, readers remember my article titled "Last line effect". It describes a pattern I've once noticed: in most cases programmers make an error in the last line of similar text blocks. Now I want t…
PVS-Studio ROI

Date: Jan 30 2019

Author: Andrey Karpov

Occasionally, we're asked a question, what monetary value the company will receive from using PVS-Studio. We decided to draw up a response in the form of an article and provide tables, which will sho…
Technologies used in the PVS-Studio code analyzer for finding bugs and potential vulnerabilities

Date: Nov 21 2018

Author: Andrey Karpov

A brief description of technologies used in the PVS-Studio tool, which let us effectively detect a large number of error patterns and potential vulnerabilities. The article describes the implementati…
The Ultimate Question of Programming, Refactoring, and Everything

Date: Apr 14 2016

Author: Andrey Karpov

Yes, you've guessed correctly - the answer is "42". In this article you will find 42 recommendations about coding in C++ that can help a programmer avoid a lot of errors, save time and effort. The au…

Comments (0)

Next comments
This website uses cookies and other technology to provide you a more personalized experience. By continuing the view of our web-pages you accept the terms of using these files. If you don't want your personal data to be processed, please, leave this site.
Learn More →