0

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

4

1 回答 1

1

在疯狂地尝试了很多东西之后,在互联网上阅读,我找到了解决方案。为了这

1)添加一个新的环境变量为:

名称 = IBM_RATIONAL_PURIFY_ENABLE_SELECTIVE

谷 = 1

2) 除了我在 OP 中提到的 MS Visual Studio 项目设置之外,还需要以下设置 -

C/C++-->代码生成=运行时库-->多线程调试/MTd

当你在purify中运行可执行文件时,你必须点击Configure Selective,选择你的exe。

然后当你运行时,它应该收集所需的错误相关信息。

-广告

于 2010-02-23T17:49:15.610 回答