Viva64: working up of 64-bit applications

6
Viva64: working up of 64-bit applications Author: Evgeniy Ryzhkov Date: 14.12.2006 At present, Viva64 and VivaMP software products are included in PVS-Studio as parts of it and are no longer distributed as separate applications. Please use PVS-Studio program to obtain the necessary possibilities of code verification. Abstract Viva64 - is a tool for searching of errors and possible problems at C/C ++ code at the applications port on the 64-bit platform. Nowadays when the necessity of the 64-bit versions software output is realized by the most of the developers, it is too important to be sure of the working up product quality. Even if the traditional 32-bit version of your product has been tested carefully, its portability on the 64-bit platform may reveal some unexpected problems. Some separate items are devoted to the applications portability problems, and this one tells how to provide the necessary level of the code quality with the help the static analyzer Viva64. The main resources Came to the necessity of the existing applications port on the new 64-bit system, the software developers meet with unusual problems. The programs that have been functioning like clock-watch for years begin to behave themselves indefinitely. Certainly a program has more main memory. Although during processing more data then earlier ones, the application may hang up, crash, or, what's worse to give out files with stuff instead of ones with the results of its work. The reason of it is in the change of some data types dimensions (primarily pointers). However to find out areas in the programs code, where of the code fulfillment sequence has changed because of it, with the help of the compiler standard expressions is impossible. The compiler can't give out warning messages at all potentially incorrect constructions, although a programmer has to find them out. The code static analyzer Viva64 comes to the aid, integrating into Visual Studio 2005, it allows: to detect incorrect construction at the code (from the 64-bit support's point of view); to give an exact and complete diagnostics up to the line number; to make navigation over the code incorrect areas; to analyze the after-effects, to which may lead the error, with the help of the full reference system, integrating into MSDN; to point out how to correct the errors with the help of the examples from the documentation; to carry out code analysis of the whole project or solution (in the Microsoft Visual Studio terminology) , but not only separate files. Viva64 - is the first in world code analyzer on the compatibility with the 64-bit systems in the world. Despite there existed early and exist now some other code analyzers (as a rule link-like ones), Viva64 is distinguished on principle by:

description

Viva64 - is a tool for searching of errors and possible problems at C/C ++ code at the applications port on the 64-bit platform. Nowadays when the necessity of the 64-bit versions software output is realized by the most of the developers, it is too important to be sure of the working up product quality. Even if the traditional 32-bit version of your product has been tested carefully, its portability on the 64-bit platform may reveal some unexpected problems. Some separate items are devoted to the applications portability problems, and this one tells how to provide the necessary level of the code quality with the help the static analyzer Viva64.

Transcript of Viva64: working up of 64-bit applications

Page 1: Viva64: working up of 64-bit applications

Viva64: working up of 64-bit

applications

Author: Evgeniy Ryzhkov

Date: 14.12.2006

At present, Viva64 and VivaMP software products are included in PVS-Studio as parts of it and are no

longer distributed as separate applications. Please use PVS-Studio program to obtain the necessary

possibilities of code verification.

Abstract Viva64 - is a tool for searching of errors and possible problems at C/C ++ code at the applications port on

the 64-bit platform. Nowadays when the necessity of the 64-bit versions software output is realized by

the most of the developers, it is too important to be sure of the working up product quality. Even if the

traditional 32-bit version of your product has been tested carefully, its portability on the 64-bit platform

may reveal some unexpected problems. Some separate items are devoted to the applications portability

problems, and this one tells how to provide the necessary level of the code quality with the help the

static analyzer Viva64.

The main resources Came to the necessity of the existing applications port on the new 64-bit system, the software

developers meet with unusual problems. The programs that have been functioning like clock-watch for

years begin to behave themselves indefinitely. Certainly a program has more main memory. Although

during processing more data then earlier ones, the application may hang up, crash, or, what's worse to

give out files with stuff instead of ones with the results of its work. The reason of it is in the change of

some data types dimensions (primarily pointers). However to find out areas in the programs code,

where of the code fulfillment sequence has changed because of it, with the help of the compiler

standard expressions is impossible. The compiler can't give out warning messages at all potentially

incorrect constructions, although a programmer has to find them out.

The code static analyzer Viva64 comes to the aid, integrating into Visual Studio 2005, it allows:

• to detect incorrect construction at the code (from the 64-bit support's point of view);

• to give an exact and complete diagnostics up to the line number;

• to make navigation over the code incorrect areas;

• to analyze the after-effects, to which may lead the error, with the help of the full reference

system, integrating into MSDN;

• to point out how to correct the errors with the help of the examples from the documentation;

• to carry out code analysis of the whole project or solution (in the Microsoft Visual Studio

terminology) , but not only separate files.

Viva64 - is the first in world code analyzer on the compatibility with the 64-bit systems in the world.

Despite there existed early and exist now some other code analyzers (as a rule link-like ones), Viva64 is

distinguished on principle by:

Page 2: Viva64: working up of 64-bit applications

• orientation exceptionally towards the search of problems in the 64

programs port as well as during the new applications working up.

• total integration with Microsoft Visual Studio

system.

• minimum setup - one needn't study settings documentation, choose check levels, or set the

numbers of the analyzing rules to work with the analyzer.

• the analyzer is ready for work just after its installation.

Let's know how it works.

Installation and setupOne can download the analyzer from the site

appreciating completely its power. The installation is not difficult, that's why a user could start

installation at ones, if it were an ordinary code analyzer. However there is the only most important

adjustment for a user in Viva64

will be necessary only after you can estimate all the possibilities of the tool.

As we have already said Viva64 integrates in Microsoft Visual Studio 2005 (picture 1) and allows

starting to work.

What we'll do.

Picture 1: Viva64 Integration in Microsoft Visual Studio 2005.

Attention! If it is necessary, a user may consult with the embedded help system about some other

settings.

orientation exceptionally towards the search of problems in the 64-bit code during the 32

as well as during the new applications working up.

total integration with Microsoft Visual Studio - files analysis, navigation over the code, help

one needn't study settings documentation, choose check levels, or set the

the analyzing rules to work with the analyzer.

the analyzer is ready for work just after its installation.

Installation and setup One can download the analyzer from the site www.Viva64.com. The evaluation version allows

appreciating completely its power. The installation is not difficult, that's why a user could start

installation at ones, if it were an ordinary code analyzer. However there is the only most important

a64 - is an input dialogue of the authorized information. But this adjustment

will be necessary only after you can estimate all the possibilities of the tool.

As we have already said Viva64 integrates in Microsoft Visual Studio 2005 (picture 1) and allows

Picture 1: Viva64 Integration in Microsoft Visual Studio 2005.

Attention! If it is necessary, a user may consult with the embedded help system about some other

bit code during the 32-bit

files analysis, navigation over the code, help

one needn't study settings documentation, choose check levels, or set the

evaluation version allows

appreciating completely its power. The installation is not difficult, that's why a user could start

installation at ones, if it were an ordinary code analyzer. However there is the only most important

is an input dialogue of the authorized information. But this adjustment

As we have already said Viva64 integrates in Microsoft Visual Studio 2005 (picture 1) and allows at once

Picture 1: Viva64 Integration in Microsoft Visual Studio 2005.

Attention! If it is necessary, a user may consult with the embedded help system about some other

Page 3: Viva64: working up of 64-bit applications

The distributive Viva64 includes a test

contains a simple program, demonstrating some classical errors. This example is installed separately

from the Viva64 folder Windows program menu.

Adjust this example.

Functioning principle of VivOpen, compile and start PortSample 32

platform Win32 and menu command "Build". After the example start switch on all the checkboxes

(picture 2) and click the button "Run". The program will

"Done". At the same time all chosen functions VXXX() with demonstrating code will be called.

And now let's compile and start 64

project Visual Studio adjustments. After clicking the button "Run" the program will behave

unpredictably and probably will crash (it depends of the computer). Its time for Viva64 to demonstrate

itself.

Open the file V1XX.cpp and choose the

"Check current file". Firstly, it'll carry out the preprocessing for macro determination opening, switching

on the header files and etc. As a preprocessing result we'll get file with the expanding ".i", which is in the

The distributive Viva64 includes a test example PortSample - a project for Visual Studio 2005, which

contains a simple program, demonstrating some classical errors. This example is installed separately

from the Viva64 folder Windows program menu.

Functioning principle of Viva64 Open, compile and start PortSample 32-bit version. In Visual Studio you should choose the type of the

platform Win32 and menu command "Build". After the example start switch on all the checkboxes

(picture 2) and click the button "Run". The program will function correctly and send the message

"Done". At the same time all chosen functions VXXX() with demonstrating code will be called.

Picture 2: Test example window.

And now let's compile and start 64-bit version of the same example, so choose the plat

project Visual Studio adjustments. After clicking the button "Run" the program will behave

unpredictably and probably will crash (it depends of the computer). Its time for Viva64 to demonstrate

Open the file V1XX.cpp and choose the command in Viva64 menu

"Check current file". Firstly, it'll carry out the preprocessing for macro determination opening, switching

on the header files and etc. As a preprocessing result we'll get file with the expanding ".i", which is in the

a project for Visual Studio 2005, which

contains a simple program, demonstrating some classical errors. This example is installed separately

bit version. In Visual Studio you should choose the type of the

platform Win32 and menu command "Build". After the example start switch on all the checkboxes

function correctly and send the message

"Done". At the same time all chosen functions VXXX() with demonstrating code will be called.

bit version of the same example, so choose the platform x64 in the

project Visual Studio adjustments. After clicking the button "Run" the program will behave

unpredictably and probably will crash (it depends of the computer). Its time for Viva64 to demonstrate

"Check current file". Firstly, it'll carry out the preprocessing for macro determination opening, switching

on the header files and etc. As a preprocessing result we'll get file with the expanding ".i", which is in the

Page 4: Viva64: working up of 64-bit applications

project folder. For the created file the analyzer will be started that will carry out the code check. After

which the results of the analyzer work will be set in the window of the ambience output Visual Studio

2005. Pay attention that you may carry out file analysis jus

another platform (for example, Win32) it will be sent a message about error. It means that for different

platforms it is possible to use different ways of carrying out the program, which are set with the he

the #ifdef/#endif constructions.

As far as for Viva64 analyzer work is necessary to carry out preprocessing, so one should make sure that

the file is compiled for the platform x64 correctly, without messages about errors.

The usage of Viva64: detect,To proceed directly with the errors detect at the open example PostSample one should choose "Check

Current Project". Firstly, it will be started the preprocessor, and then the analyzer. The results of its

work are shown in the output window (picture 3).

And this is the first:

error V101: Implicit assignment type conversion to memsize type.

Let's look at the code in this place.

unsigned imageWidth = 1000;

unsigned imageHeght = 1000

unsigned bytePerPixel = 3;

unsigned maxFrameCountInBuffer;

. For the created file the analyzer will be started that will carry out the code check. After

which the results of the analyzer work will be set in the window of the ambience output Visual Studio

2005. Pay attention that you may carry out file analysis just for the platform x64. In case of file check for

another platform (for example, Win32) it will be sent a message about error. It means that for different

platforms it is possible to use different ways of carrying out the program, which are set with the he

the #ifdef/#endif constructions.

As far as for Viva64 analyzer work is necessary to carry out preprocessing, so one should make sure that

the file is compiled for the platform x64 correctly, without messages about errors.

The usage of Viva64: detect, analysis and errors correction in the codeTo proceed directly with the errors detect at the open example PostSample one should choose "Check

Current Project". Firstly, it will be started the preprocessor, and then the analyzer. The results of its

e shown in the output window (picture 3).

Picture 3: Output Window.

error V101: Implicit assignment type conversion to memsize type.

Let's look at the code in this place.

unsigned imageWidth = 1000;

unsigned imageHeght = 1000;

unsigned bytePerPixel = 3;

unsigned maxFrameCountInBuffer;

. For the created file the analyzer will be started that will carry out the code check. After

which the results of the analyzer work will be set in the window of the ambience output Visual Studio

t for the platform x64. In case of file check for

another platform (for example, Win32) it will be sent a message about error. It means that for different

platforms it is possible to use different ways of carrying out the program, which are set with the help of

As far as for Viva64 analyzer work is necessary to carry out preprocessing, so one should make sure that

the file is compiled for the platform x64 correctly, without messages about errors.

analysis and errors correction in the code To proceed directly with the errors detect at the open example PostSample one should choose "Check

Current Project". Firstly, it will be started the preprocessor, and then the analyzer. The results of its

error V101: Implicit assignment type conversion to memsize type.

Page 5: Viva64: working up of 64-bit applications

if (IsX64Platform()) {

maxFrameCountInBuffer = 2000;

} else {

maxFrameCountInBuffer = 100;

}

size_t bufferSize = imageWidth * imageHeght * // 34

bytePerPixel * maxFrameCountInBuffer;

The error is given on the line with the declaration of the variable bufferSize. We see that the variable

maxFrameCountInBuffer for 64-bit platform has a value 2000.

This is admissible, because after the multiplying of all the variables we expect to get 64-bit figure (buffer

size), but ... we'll get only 32-bit one. As a result the variable bufferSize will never expend 4 Gb. Although

it itself is a 64-bit type. Pay attention that the compiler gives nothing on this line even at the highest

diagnostics level. And Viva64 says about the error here. If you are not sure that you absolutely realize

the types digit capacity problem, push F4, and the embedded help system will be opened Viva64, where

is given the detailed error description with the recommendations of its correction.

Let's continue studying the example, so push F4 once more. Move to the message:

error V102: Usage non memsize type for pointer arithmetic.

Let's check the code which is at the line 71:

int domainWidth;

int domainHeght;

int domainDepth;

...

char *buffer;

...

char *current = buffer;

char *end = buffer;

end += domainWidth * domainHeght * domainDepth; // 71

Here is another problem. From the error description we see that for the pointer arithmetic is used the

type not intended for it. In this case the pointer arithmetic is carried out with 32-bit type int, but it

should be used 64-bit one. Data types, using for the work with the pointers, and also for the keeping of

the object sizes (for examples, arrays) in Viva64 are called memsize-types. At the reference system the

memsize-types usage is examined carefully.

Let's look in the help system how to correct the present error. Here are given advices how to change the

types, which take part in such arithmetic. The example correction is in the change of the variable type

Page 6: Viva64: working up of 64-bit applications

domainWidth, domainHeigh, domainDepth for the type ptrdiff_t or in the usage of the explicit type

conversation. In all the analyzer will give out more than dozens error messages at the PostSample

project.

And what is the compiler? The compiler Microsoft Visual C++ 2005 with the switched on diagnostics of

the port problems (the key /Wp64) and the maximum level of the diagnostics messages (the key /W4)

gives out for the entire project... only three diagnostics messages, that are also caught by the analyzer

Viva64. This leads that the most errors stay undetected during the applications port on the 64-bit

platform without using Viva64.

Viva64's position in the process of the software working up There are two ways of Viva64 usage at the working up process: in the case of the prepared 32-bit

application on the 64-bit platform and in the case of the working up new 64-bit application.

The 32-bit application port should be carried out in such a way:

• prepare the project in the Studio Visual 2005, which is build correctly for the platform Win32;

• add a new platform x64 to the project, build the project, fixing all compiler errors;

• switch on the maximum warning level (/Wp64, Detect 64-Bit Portability Issues), correct the

errors;

• with the help of Viva64 carry out all possible errors detect, analyze them and correct;

• move to the application testing.

In the case of a new 64-bit application enduring it is reasonable not to wait for the end of the working

up, but to use Viva64 for the working up code control. Moreover one may check as well as the whole

project or decision, and the separate more important code parts.

Viva64 is not a silver bullet and what is next... It is necessary to notice that Viva64 doesn't solve all the problems, appearing at the 64-bit software

enduring:

• Viva64 can't replace full testing;

• Viva64 knows about the most errors, but not about all;

• Viva64 should be used by the developer, understanding all work computer principles.

In other words, if you correct all the errors at the code with the help of Viva64, shouldn't consider that

the application has been already prepared and it doesn't need diagnostics.

Although Viva64 can really raise the quality of the working up software, enduce the error number and

hasten the time of the product output at the market.