Catch the obscure problems in your program before you release it – Use Visual Studio’s inbuilt ‘Code Analysis’ Tool

Catch the obscure problems in your program before you release it – Use Visual Studio’s inbuilt ‘Code Analysis’ Tool

Every developer should maintain his/her code quality and to do so the first step can be to review code my self with the help of the Code Analysis tool. Code Analysis will help to improve your code quality and avoid common problems which are not trapped in the compilation.

There are many different free and commercial tools available for the Code Analysis for both managed and unmanaged source code. But I am using the Code Analysis tool which as it is inbuilt with Visual Studio.

Visual Studio Code analysis tool is a static analyzer, which means it depends completely on source code and no need to execute our application.

This tool warns developers about possible errors in the source code which are not handled yet.

Major errors developer should look for are using uninitialized memory, buffer overruns, dereferencing a copy of a null pointer, Array-new scalar-delete mismatch, memory leaks, and resource leaks.

This tool supports both managed and unmanaged source code.

Code Analysis Menu

You can either run Code Analysis for a complete solution or for a single project from a solution.

Project Properties Menu

 

Here you can set the desired rule set for Code Analysis. You can also create your custom Code Analysis rule set.

Code Analysis Results

Once code analysis is completed warnings will be displayed in the Code Analysis window. The developer needs to just click on the warning to go to the exact line of code having warning and resolve it with the help of description provided in the window. You can copy all the warnings to a text file for future reference.

Links for reference:

https://msdn.microsoft.com/en-in/library/6yz6c9dy(v=vs.100).aspx

https://msdn.microsoft.com/en-in/library/dd264939(v=vs.100).aspx

https://msdn.microsoft.com/en-in/library/dd547177(v=vs.100).aspx

Video tutorial from Microsoft:

https://channel9.msdn.com/events/BUILD/BUILD2011/TOOL-100T

Author : Vijay S.
Contact us:
info@prototechsolutions.com
ProtoTech Solutions