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.

New diagnostic functions implemented in…

New diagnostic functions implemented in PVS-Studio 3.60

Jun 11 2010

New diagnostic functions implemented in PVS-Studio 3.60.

1. Deprecated functions

The V303 diagnostic message.

In the Win64 API, there are some functions which are present for the compatibility purpose but might cause errors in 64-bit programs. A typical example is the SetWindowLong function.

LONG SetWindowLong(HWND hWnd, int nIndex, LONG dwNewLong);

The SetWindowLong function changes attributes of the defined window. The function also sets a 32-bit value of the LONG type at the defined shift in an additional space of memory about the window. It is often a pointer which is saved. It is safe in Win32 systems since the size of the LONG type coincides with the pointer's size. But when recompiling the code for a Win64 system, a call of this function might cause an error. Let's consider a code sample taken from a real application:

SetWindowLong(window, 0, (LONG)this);

The code is correct from the viewpoint of the Win32 system but it may cause an error in the 64-bit version of the program. Whether an error will occur or not depends upon what memory section the object referred to by the "this" pointer is created in. If the object will be created outside the first 4 Gbytes of the address space, it will lead to an unexpected behavior of the program or its crash. What is unpleasant about this error is that it might occur rarely or after a long time during program execution when objects will be created outside the first 4 Gbytes due to memory allocation.

To correct the code, you should use a new extended version of the function SetWindowLongPtr whose third parameter has the LONG_PTR type.

Beginning with the 3.60 version, the Viva64 analyzer included into PVS-Studio allows you to quickly find functions that require programmer's attention when developing 64-bit programs. To such functions, the following ones refer: SetWindowLong, GetWindowLong, SetClassLong, GetClassLong, GetFileSize and some other functions.

The following diagnostic message is intended to detect these functions: "V303: The function is deprecated in the Win64 system. It is safer to use the NewFOO function". Instead of NewFOO, analyzer writes the name of the recommended function, for example, "GetFileSizeEx".

2. Buffer overflow

The V320 diagnostic message.

Unfortunately, the errors of buffer overflow or its incomplete processing are rather frequent type of defects in programs written in the C and C++ languages. But we are interested at the moment in those errors that occur when porting applications to a 64-bit system. Such errors occur most often due to misprints or inaccuracy of the programmer. Consider an example:

STRUCT_1 Abcd;
STRUCT_2 Qwer;
memset(&Abcd, 0, sizeof(Abcd));
memset(&Qwer, 0, sizeof(Abcd));

In this code, the two structures are zeroed. When filling the second structure, the size of the first structure is used. While the sizes of the first and second structures coincide in the 32-bit code, the program works correctly. In the 64-bit program, the structures' sizes might differ and it will lead to a crash.

In some cases, the Viva64 analyzer allows to detect such errors and warn you by displaying the message " V320: A call of the FOO function will lead to a buffer overflow or underflow in a 64-bit system". Instead of FOO, analyzer writes the names of such functions as memset, memcpy, memmove, etc.

In some cases, the V320 warning will let you detect an error that is present both in the 64-bit and 32-bit versions and was not found earlier. Below is an example of an error found in the code of a real application while testing Viva64:

struct MD5Context
  unsigned int buf[4];
  unsigned int bits[2];
  unsigned char in[64];
MD5Context *ctx;
memset(ctx, 0, sizeof(ctx)); //V320

The error lies in using the "sizeof(ctx)" expression instead of "sizeof(*ctx)". It means that only a small part of the structure will be zeroed both in the 32-bit and 64-bit versions of the application.

3. Memsize-types in structures

The V122 diagnostic message.

This rule is rather specific and in 99% gives a false alarm. That is why it is disabled by default.

The V122 diagnostic message is generated for all the memsize-types (size_t, intptr_t, INT_PTR, DWORD_PTR, pointers, etc.) present in structures or classes. Presence of a pointer in a structure does not necessarily imply an error. However, it means that the structure's size changes and sometimes users would like to view a list of all such structures.

Consider an example where the "V122. Memsize type is used in the struct/class" message will be displayed:

struct Header
  unsigned m_version;
  size_t m_bodyLen; //V122

4. Users' wishes

The V2001 and V2002 diagnostic messages.

For the first time we implemented diagnostic rules in PVS-Studio that do not refer to detecting errors in 64-bit or parallel applications. These are general-purpose diagnostic messages which were created on the request of our customers. We implemented wishes of our current and potential customers in the PVS-Studio before as well, but they all concerned 64 bits or parallelism.

We think that it is the beginning of a new stage of cooperation with our users. We begin not only to ship and modify PVS-Studio but also to implement absolutely new types of diagnostic capabilities our users are interested in.

The V2001 and V2002 rules are rather specific and most likely will not be interesting among many programmers. However, we hope that you will notice that we are open to cooperation and will contact us and share your wishes. We are ready to develop specialized extensions for PVS-Studio and even separate solutions in the sphere of static code analysis. To learn more, please contact us by the e-mail or through the feedback form.

P.S. Do not forget to try the "What is it?" function.

Popular related articles
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…
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…
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…
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…
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…
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…
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…
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…
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…

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 →