This might not appear like a programming question, but inherently deals with code.
I have a following piece of test-code, which has obvious errors like array index out of bounds, memory leak:-
#include "stdio.h"
#include "stdlib.h"
main()
{
int i;
char *ptr;
ptr = (char*)malloc(5);
for(i=0;i<10;i++)
{
ptr[i]=(char)i;
}
}
This code is built on a MS-Visual Studio 2008.
I am trying to use Rational Purify (version 7.0) to identify run-time errors, memory leaks in my code. Towards after reading some pointers about how to build code for usage in Purify, i have done below things in the MSVS-2008 project settings:-
1.)Disable incremental link 2.) Debug information compiler flag is /Zi
3.) Set the Linker option - "Basic run-time checking to value Default.
4.) Added a extra linker option /fixed:no.
5.) Build config is debug, no optimization enabled.
Then i build and get the exe. I use this exe to run in Purify so that it instruments the same. But the output window in purify after running/instrumenting this exe, shows no errors about memory leak, ..etc which are present in the code above.
The purify output window shows output of different binaries (my exe file and some other system dlls) it instrumented loaded, executed. But in the output where is shows data about my exe, there is no error message.
My feeling is i am making a mistake in giving compilation/linker options while building the exe in MS-VS 2008.or The generated executable format is not compatible/understandable by Purify?
1.)What could be wrong here? What more options i could need while building the exe?
2.)Is my process of using Purify correct, or am i missing something? How can i get Purify to show all the errors in my program after doing run time analysis?
3.)Is there any other tool (free/commercial license)which can detecl memory leaks, array out of bound errors, use of uninitialized pointers, variables, memory corruption etc.. by doing run time analysis of C code.
Sorry for longish mail, but had to be clear.
thanks.
-AD
After furiously trying many things, reading on internet, i found out the soln. for this
1) Add a new environment variable as :
Name = IBM_RATIONAL_PURIFY_ENABLE_SELECTIVE
Vale = 1
2) Apart from the MS Visual Studio project settings which i mentioned in the OP, below setting is needed -
C/C++-->Code Generation = Run time library --> Multi-threaded Debug /MTd
And when u run the executable in purify, you have to click on Configure Selective, select your exe.
Then when u run, it should colelct the required error related information.
-AD