本文主要是介绍实例介绍利用valgrind定位变量未初始化的问题,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
继续介绍valgrind的用途, 看程序:
#include <stdio.h>
#include <string.h>int main()
{int i;if(i == 0){printf("[%d]\n", i);}return 0;
}
一眼就能看出程序的问题, valgrind分析如下:
[root@xxx ~/valgrind-3.8.1/bin]# g++ -g test.cpp
[root@xxx ~/valgrind-3.8.1/bin]#
[root@xxx ~/valgrind-3.8.1/bin]# ./valgrind --tool=memcheck --leak-check=yes --show-reachable=yes ./a.out
==8088== Memcheck, a memory error detector
==8088== Copyright (C) 2002-2012, and GNU GPL'd, by Julian Seward et al.
==8088== Using Valgrind-3.8.1 and LibVEX; rerun with -h for copyright info
==8088== Command: ./a.out
==8088==
==8088== Conditional jump or move depends on uninitialised value(s)
==8088== at 0x4005B0: ma
这篇关于实例介绍利用valgrind定位变量未初始化的问题的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!