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 that, after reading some pointers about how to build code for usage in Purify, i have done below things in the MSVS-2008 project settings:-
- Disable incremental link
- Debug information compiler flag is /Zi
- Set the Linker option - "Basic run-time checking to value Default.
- Added a extra linker option /fixed:no.
- 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?
What could be wrong here? What more options i could need while building the exe?
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?
Is there any other tool (free/commercial license) which can detect 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.