实例介绍利用valgrind定位变量未初始化的问题

本文通过实例详细解析如何运用valgrind工具来定位并解决程序中变量未初始化的问题,帮助提升代码质量。
摘要由CSDN通过智能技术生成

       继续介绍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
  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值