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--
USD
EUR
GBP
RUB
* 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.

>
>
Testing of Linux-applications with the …

Testing of Linux-applications with the help of PVS-Studio in Windows

Aug 06 2009

Quite recently we have released a new program product PVS-Studio which united our two analyzers Viva64 and VivaMP. When Viva64 analyzer intended for developers of 64-bit applications was a separate product yet, we were asked this question: "Is there a version of Viva64 for Linux?". And although it is possible to create such a version (as development of a separate solution for a particular client) there is no Linux-version of the analyzer for the moment.

But sometimes you can test the code of Linux-applications in 64-bit Linux environment in Windows system. It is this possibility our engineers are working at. In this note I will tell you how it works.

From the viewpoint of developing 64-bit applications Windows and Linux operation systems differ in the data model being used. This is a correlation between the sizes of basic data types in a particular system. In the 64-bit Windows-version LLP64 data model is used. In this data model the types have the following sizes: int - 32 bits, long - 32 bits, long long - 64 bits, size_t - 64 bits, pointer - 64 bits. In the 64-bit Linux-version LP64 data model is used. In it the data types' sizes are the following: int - 32 bits, long - 64 bits, long long - 64 bits, size_t - 64 bits, pointer - 64 bits. For 64-bit Linux and Windows systems such types as long double are also different but it is not relevant here. As you can see, the basic difference is in the size of long type - in 64-bit Windows it is 32 bits and in 64-bit Linux it is 64 bits.

By default, Viva64 code analyzer (and now PVS-Studio) is oriented on LLP64 data model being intended for operation in Windows environment. Roughly speaking, it means that it searches incorrect shared use of size_t-types and int-types. To test the code on correctness in 64-bit Linux-environment you need to search incorrect shared use of long-types and int-types as well.

We plan to add the possibility of searching incorrect shared use of long-types into the new version of PVS-Studio 3.10. It will be a special operation mode, the so called "Linux-like mode". The analyzer of 64-bit problems will operate in this mode in the same way as it would operate in Linux-environment. It will allow you to partly test the code of applications operating in Linux in Windows system with the help of PVS-Studio.

So, to test a 64-bit Linux-application you will need to have its version compiled into Visual Studio. That is, such testing is reasonable for cross-platform applications which are built both in Windows and Linux.

Of course, testing of an application on 64-bit code correctness in the mode of imitating Linux-environment cannot be considered full and guarantee its efficiency in real Linux-world. Besides, there can be more false responses. But in some cases this testing variant will help you find a lot of errors which would occur in 64-bit Linux-systems.

The disadvantage of this approach is code sections which are not built for Windows. For example, it can be interface parts of a program. You cannot test them in Windows because you cannot compile them. But, for example, you can test the core of a program which operates both in Windows and Linux.

You should also keep in mind that in Linux-like data model only user code is tested. The code included into system include-files in Windows will still be the same as for LLP64 memory model. For all the files are processed by the preprocessor before analysis and of course it does not know about LP64 model.

To demonstrate the peculiarities of using PVS-Studio in "Linux-like mode" I will give some examples.

void foo(ptrdiff_t delta);
int i = -2;
unsigned k = 1;
foo(i + k);

This code will be potentially unsafe both for Windows and Linux systems. An incorrect result occurs at implicit extension of the actual argument having the value 0xFFFFFFFF of unsigned type to ptrdiff_t type. In this case the warning will be shown independently from the mode being used.

void *ptr;
long np = (long)(ptr);

This code diagnosed as incorrect in 64-bit Windows programs will be correct for 64-bit Linux-systems.

Vice versa, the next example shows the code correct for Windows systems and incorrect for Linux ones:

long array[4] = { 1, 2, 3, 4 };
enum ENumbers { ZERO, ONE, TWO, THREE, FOUR };
int *intPtr = (int *)(array);
cout << intPtr[1] << endl;

As the sizes of int and long in 64-bit Linux systems do not coincide, the analyzer will show the corresponding diagnostic warning.

The last two examples demonstrate the limitations of the new operation mode:

#ifdef _WINDOWS
  typedef long MY_SIGNED_32;
#else //Linux
  typedef int MY_SIGNED_32;
#endif

As the preprocessor will choose the branch "typedef long MY_SIGNED_32;" all the code constructions containing MY_SIGNED_32 type will be incorrect from the viewpoint of Linux systems.

And finally we can give a simpler example when the code we need to analyze will not be analyzed:

#ifdef LINUX_64
   // there is too much code here
#endif

Despite the limitations we have listed, the ability of working both with the Windows-traditional LLP64 data model and Linux-traditional LP64 data model will help you broaden the scope of use of our code analyzer. You should just understand how this option operates and what it can and cannot provide.

By default, the new mode will be switched off and those users for whom operation in Linux-environment is not relevant, can forget about it.

Popular related articles
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…
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…
Appreciate Static Code Analysis!

Date: Oct 16 2017

Author: Andrey Karpov

I am really astonished by the capabilities of static code analysis even though I am one of the developers of PVS-Studio analyzer myself. The tool surprised me the other day as it turned out to be sma…
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…
The Last Line Effect

Date: May 31 2014

Author: Andrey Karpov

I have studied many errors caused by the use of the Copy-Paste method, and can assure you that programmers most often tend to make mistakes in the last fragment of a homogeneous code block. I have ne…
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…
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…
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…
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…

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 →
Accept