请教关于Rational Purify的使用问题,谢谢!
刚学习使用Rational Purify,安装后使用它自带的一个测试程序hello.exe测试后测试结果如下:
[I] Starting Purify'd C:\Program Files\Rational\PurifyPlus\Samples\Purify\hello.exe at 2008-05-27 11:25:10
[I] Starting main
[W] UMR:Uninitialized memory read in strlen {1 occurrence}
[E] ABW: Array bounds write in WinMain {4 occurrences}
[E] ABR: Array bounds read in strlen {1 occurrence}
[W] PAR: GetVersionExA(0x77fad298) OSVERSIONINFOA structure size field was not initialized {2 occurrences}
[I] Summary of all memory in use... {532325 bytes, 249 blocks}
[I] Summary of all memory leaks... {10 bytes, 1 block}
[I] Exiting with code 0 (0x00000000)
[I] Program terminated at 2008-05-27 11:25:16
由于不知怎么粘贴图片,所以只能将结果粘上来,前面的[]中的内容实际上是对应的图标。
其中hello的代码如下:
#include <windows.h>
WINAPI
WinMain(
HINSTANCE hInstance, // handle of current instance
HINSTANCE hPrevInstance, // handle of previous instance
LPSTR lpszCmdLine, // address of command line
int nCmdShow // show state of window
)
{
int i;
size_t length;
char *string1 = "Hello, Windows";
char *string2 = malloc(10);
length = strlen(string2); // UMR because string2 is not initialized.
for (i = 0; string1[i] != '\0'; i++) {
string2[i] = string1[i]; // ABW's generated on this line.
}
length = strlen(string2); // ABR generated on this line.
MessageBox(NULL, "Hello, Windows", "The Windows Hello Dialog", MB_OK | MB_ICONINFORMATION);
return 0;
}
但是如果我将上述代码修改为如下形式:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
int i;
size_t length;
char *string1 = "Hello, Windows";
char *string2 = (char*)malloc(10);
length = strlen(string2); // UMR because string2 is not initialized.
for (i = 0; string1[i] != '\0'; i++) {
string2[i] = string1[i]; // ABW's generated on this line.
}
length = strlen(string2); // ABR generated on this line.
return 0;
}
使用Rational Purify的测试结果如下:
[I] Starting Purify'd E:\问题总汇\内存泄漏工具\CodeTest\test3\Debug\test3.exe at 2008-05-27 11:34:08
[I] Starting main
[I] Summary of all memory in use... {6614 bytes, 46 blocks}
[I] Exiting with code 0 (0x00000000)
[I] Program terminated at 2008-05-27 11:34:11
从这个结果看,程序没有任何问题。
我不知道这个是什么原因造成的?另外还有就是一些很简单的程序这个工具都测不出来?是不是需要对这个工具进行一些配置呀?
还请各位高手帮忙!