请教关于Rational Purify的使用问题,谢谢!

rabbit729 2008-05-27 11:36:31
刚学习使用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
从这个结果看,程序没有任何问题。

我不知道这个是什么原因造成的?另外还有就是一些很简单的程序这个工具都测不出来?是不是需要对这个工具进行一些配置呀?
还请各位高手帮忙!
...全文
97 1 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
rabbit729 2008-05-27
  • 打赏
  • 举报
回复
自己顶一下

65,186

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧