C库中的Valgrind错误? [英] Valgrind errors in c libraries?

查看:110
本文介绍了C库中的Valgrind错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Valgrind显示大小为8的错误的未初始化值. 偶尔,下面的条件跳转会导致未初始化的值错误.

Valgrind is showing an uninitialised value of size 8 error. And occasionally, the below conditional jump on uninitialised value error.

我要做的就是使用gcc随附的stdc ++库打印格式化的字符串 以及内置的vsnprintf.

All I'm doing is printing a formatted string using the stdc++ library that comes with gcc and the built in vsnprintf.

这位于称为format的方法内,该方法是自定义字符串类的一部分. 现在怎么办?一切看起来都正确.错误似乎在_itoa.c内部.但是我可以想到的是,在外面所做的就是不使用此功能,这不太可能!

This is inside a method called format which is part of a custom string class. What now? everything looks correct. Error seems to be inside _itoa.c. But all I can think of to do on the outside is not use this function, which is not very possible!

==4229== Memcheck, a memory error detector
==4229== Copyright (C) 2002-2009, and GNU GPL'd, by Julian Seward et al.
==4229== Using Valgrind-3.6.0.SVN-Debian and LibVEX; rerun with -h for copyright info
==4229== Command: ./test
==4229== 
==4229== Use of uninitialised value of size 8
==4229==    at 0x54A3DF1: _itoa_word (_itoa.c:196)
==4229==    by 0x54A5138: vfprintf (vfprintf.c:1613)
==4229==    by 0x555C74F: __vsnprintf_chk (vsnprintf_chk.c:65)
==4229==    by 0x407E57: myString::format(char const*, ...) (stdio2.h:79)
==4229==    by 0x419D14: ID::toString() (id.cpp:151)
==4229==    by 0x41D03D: main (test.cpp:126)
==4229== 
==4229== Conditional jump or move depends on uninitialised value(s)
==4229==    at 0x54A3DF8: _itoa_word (_itoa.c:196)
==4229==    by 0x54A5138: vfprintf (vfprintf.c:1613)
==4229==    by 0x555C74F: __vsnprintf_chk (vsnprintf_chk.c:65)
==4229==    by 0x407E57: myString::format(char const*, ...) (stdio2.h:79)
==4229==    by 0x419D14: ID::toString() (uuid.cpp:151)
==4229==    by 0x41D03D: main (test.cpp:126)
==4229== 
==4229== 
==4229== HEAP SUMMARY:
==4229==     in use at exit: 0 bytes in 0 blocks
==4229==   total heap usage: 6 allocs, 6 frees, 1,340 bytes allocated
==4229== 
==4229== All heap blocks were freed -- no leaks are possible
==4229== 
==4229== For counts of detected and suppressed errors, rerun with: -v
==4229== Use --track-origins=yes to see where uninitialised values come from
==4229== ERROR SUMMARY: 3 errors from 2 contexts (suppressed: 4 from 4)

推荐答案

这是C库中实际查看您的数字以将其格式化为字符串的位置,它表示您所使用的数字格式化来自未初始化的存储.

This is the place in the C library where it is actually looking at your number in order to format it as a string, and it indicates that the number you are formatting came from uninitialized storage.

添加valgrind选项--track-origins=yes,以获取有关未初始化值的来源的更多详细信息.

Add the valgrind option --track-origins=yes for more details on the origin of the uninitialized value.

因为通常在未初始化的内存周围进行复制,例如在结构中填充时,valgrind跟踪未初始化值的复制,并且直到实际使用该值时才抱怨,这种方式可能会影响程序的外部可见行为.这可能会使确定未初始化值的原始来源引起混淆,因为未完成值在执行其他操作之前可能已经被复制了好几次.选项--track-origins=yes跟踪其他信息,以查明未初始化值的来源,以便在未使用值最终被使用的情况下可以显示该信息.

Because it is common to copy around uninitialized memory, e.g. padding in structures, valgrind tracks copying of uninitialized values and does not complain until the point where the value is actually used in a way that might affect your program's externally-visible behavior. This can make it confusing to determine the original source of the uninitialized value, since it may have been copied several times before anything else was done with it. The option --track-origins=yes tracks additional information to pinpoint the origin of the uninitialized value, so that this can be displayed in the event that the uninitialized value ends up being used.

这篇关于C库中的Valgrind错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆