Hello,

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

Recommended Answers

All 2 Replies

I'm pretty sure you don't have a memory leak...an array out of bounds yes but memory leak no...

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.

PC-lint does many of the things you mention, but as static analysis and not as run-time.

A sample output for the code you posted:

main.c 10 error 662: (Warning -- Possible creation of out-of-bounds pointer (5 beyond end of data) by operator ')
main.c 10 error 613: (Warning -- Possible use of null pointer 'ptr' in left argument to operator ')
main.c 10 error 661: (Warning -- Possible access of out-of-bounds pointer (5 beyond end of data) by operator ')
main.c 13 error 533: (Warning -- function 'main(void)' should return a value (see line 3))
main.c 13 error 429: (Warning -- Custodial pointer 'ptr' (line 6) has not been freed or returned)

[edit]I've also seen http://en.wikipedia.org/wiki/Electric_Fence mentioned frequently.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.